]> git.tuebingen.mpg.de Git - misma.git/blob - misma.h
Fix seconds_to_human().
[misma.git] / misma.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 #define _GNU_SOURCE
3 #include <stdio.h>
4 #include <stdbool.h>
5 #include <assert.h>
6 #include <stdlib.h>
7 #include <inttypes.h>
8 #include <sys/types.h>
9 #include <pwd.h>
10 #include <stdarg.h>
11 #include <unistd.h>
12 #include <errno.h>
13 #include <string.h>
14 #include <limits.h>
15 #include <sys/uio.h>
16 #include <sys/wait.h>
17 #include <time.h>
18
19 #include "config.h"
20
21 __attribute__ ((warn_unused_result))
22 void *xrealloc(void *p, size_t size);
23
24 __attribute__ ((warn_unused_result))
25 void *xmalloc(size_t size);
26
27 __attribute__ ((warn_unused_result))
28 void *xzmalloc(size_t size);
29
30 void *xstrdup(const char *s);
31
32 __attribute__ ((format (printf, 1, 2))) __attribute__ ((warn_unused_result))
33 char *msg(const char *fmt, ...);
34
35 __attribute__ ((noreturn))
36 void die_empty_arg(const char *opt);
37
38 __attribute__ ((noreturn))
39 void die_range(const char *opt);
40
41 void check_range(uint32_t val, uint32_t min, uint32_t max, const char *opt);
42 bool xexec(char * const argv[], char **buf);
43
44 enum lvm_scope {
45         LS_GLOBAL, LS_VG, LS_POOL, LS_ORIGIN
46 };
47 struct lvmspec {
48         enum lvm_scope scope;
49         char *vg, *pool, *tlv;
50 };
51 void parse_lvmspec(const char *arg, const char *context,
52                 struct lvmspec *result);
53 void free_lvmspec(struct lvmspec *spec);
54 struct percentage_pair {
55         uint8_t data, meta;
56 };
57 struct threshold_arg {
58         struct lvmspec lvmspec;
59         struct percentage_pair threshold;
60 };
61 void parse_threshold_arg(const char *arg, const char *context,
62                 struct threshold_arg *result);
63 struct time_arg {
64         struct lvmspec lvmspec;
65         uint32_t seconds;
66 };
67 unsigned parse_timespec(const char *spec, const char *context);
68 void parse_time_arg(const char *arg, const char *context,
69                  struct time_arg *result);
70
71 void valid_fd012(void);
72 int daemonize(const char *logfile);
73 bool misma_lock(const char *string);
74 pid_t get_misma_pid(const char *string);
75 struct line_iter {
76         char *base;
77         char *line;
78 };
79 void line_iter_init(struct line_iter *liter, char *text);
80 char *line_iter_get(struct line_iter *liter);
81 bool fd2buf(int fd, char **buf);
82
83 enum loglevels {LOGLEVELS, NUM_LOGLEVELS};
84
85 __attribute__ ((format (printf, 2, 3)))
86 void misma_log(int ll, const char* fmt,...);
87
88 #define DEBUG_LOG(f,...) misma_log(LL_DEBUG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
89 #define INFO_LOG(f,...) misma_log(LL_INFO, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
90 #define NOTICE_LOG(f,...) misma_log(LL_NOTICE, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
91 #define WARNING_LOG(f,...) misma_log(LL_WARNING, "%s: " f, __FUNCTION__, ##  __VA_ARGS__)
92 #define ERROR_LOG(f,...) misma_log(LL_ERROR, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
93 #define CRIT_LOG(f,...) misma_log(LL_CRIT, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
94 #define EMERG_LOG(f,...) misma_log(LL_EMERG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
95
96 __attribute__ ((noreturn))
97 __attribute__ ((format (printf, 1, 2)))
98 void die(const char *fmt, ...);
99
100 __attribute__ ((noreturn))
101 __attribute__ ((format (printf, 1, 2)))
102 void die_errno(const char *fmt, ...);
103
104 struct heap;
105 struct heap *heap_init(void *array, unsigned num_elements,
106         int (*compare)(const void *data1, const void *data2));
107 unsigned heap_num_elements(const struct heap *h);
108 void heap_insert(void *new_element, struct heap *h);
109 void *heap_min(const struct heap *h);
110 void *heap_extract_min(struct heap *h);
111 void heap_dump(const struct heap *h, void (*dumper)(const void *));