Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this user
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux
/
mxq
Public
forked from
mariux64/mxq
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
0
Security
Insights
Issues
Additional navigation options
Code
Pull requests
Actions
Projects
Security
Insights
Issues
Files
issues/issue15
manpages
mysql
web
.gitignore
LICENSE
Makefile
README.md
mx_flock.c
mx_flock.h
mx_getopt.c
mx_getopt.h
mx_log.c
mx_log.h
mx_mysql.c
mx_mysql.h
mx_util.c
mx_util.h
mxq.h
mxq_group.c
mxq_group.h
mxq_job.c
mxq_job.h
mxq_log.c
mxqadmin.c
mxqd.c
mxqd.h
mxqdctl-hostconfig.sh
mxqdump.c
mxqkill.c
mxqsub.c
os-release
test.c
test_mx_log.c
test_mx_mysql.c
test_mx_util.c
Breadcrumbs
mxq
/
mx_util.h
Blame
Blame
Latest commit
History
History
193 lines (155 loc) · 6.45 KB
Breadcrumbs
mxq
/
mx_util.h
Top
File metadata and controls
Code
Blame
193 lines (155 loc) · 6.45 KB
Raw
#ifndef __MX_UTIL_H__ #define __MX_UTIL_H__ 1 #include <stdlib.h> #include <stdint.h> #include <stdarg.h> #include <string.h> #include <stdio.h> #include "mx_log.h" struct proc_pid_stat { long long int pid; /* 1 */ char *comm; /* 2 (comm) */ char state; /* 3 "RSDZTW" */ long long int ppid; /* 4 */ long long int pgrp; /* 5 */ long long int session; /* 6 */ long long int tty_nr; /* 7 */ long long int tpgid; /* 8 */ unsigned long long int flags; /* 9 */ unsigned long long int minflt; /* 10 */ unsigned long long int cminflt; /* 11 */ unsigned long long int majflt; /* 12 */ unsigned long long int cmajflt; /* 13 */ unsigned long long int utime; /* 14 */ unsigned long long int stime; /* 15 */ long long int cutime; /* 16 */ long long int cstime; /* 17 */ long long int priority; /* 18 */ long long int nice; /* 19 */ long long int num_threads; /* 20 */ long long int itrealvalue; /* 21 */ unsigned long long int starttime; /* 22 */ unsigned long long int vsize; /* 23 */ long long int rss; /* 24 */ unsigned long long int rsslim; /* 25 */ unsigned long long int startcode; /* 26 */ unsigned long long int endcode; /* 27 */ unsigned long long int startstack; /* 28 */ unsigned long long int kstkesp; /* 29 */ unsigned long long int kstkeip; /* 30 */ unsigned long long int signal; /* 31 */ unsigned long long int blocked; /* 32 */ unsigned long long int sigignore; /* 33 */ unsigned long long int sigcatch; /* 34 */ unsigned long long int wchan; /* 35 */ unsigned long long int nswap; /* 36 */ unsigned long long int cnswap; /* 37 */ long long int exit_signal; /* 38 */ long long int processor; /* 39 */ unsigned long long int rt_priority; /* 40 */ unsigned long long int policy; /* 41 */ unsigned long long int delayacct_blkio_ticks; /* 42 */ unsigned long long int guest_time; /* 43 */ long long int cguest_time; /* 44 */ }; #ifdef MX_NDEBUG # include <assert.h> # define mx_assert_return_minus_errno(test, eno) \ assert(test) # define mx_assert_return_NULL(test, eno) \ assert(test) #else # define mx_assert_return_minus_errno(test, eno) \ do {\ if (!(test)) {\ errno=(eno);\ mx_log_emerg("%s:%d:%s(): Assertion '" #test "' failed . Returning -(errno=" #eno ") [%d]: %m", __FILE__, __LINE__, __func__, -errno);\ return -errno;\ }\ } while (0) # define mx_assert_return_NULL(test, eno) \ do {\ if (!(test)) {\ errno=(eno);\ mx_log_emerg("%s:%d:%s(): Assertion '" #test "' failed. Setting errno=" #eno " [%d] and returning NULL: %m", __FILE__, __LINE__, __func__, errno);\ return NULL;\ }\ } while (0) #endif #define mx_debug_value(fmt, v) mx_log_debug("mx_debug_value: " #v " = " fmt, v) #undef mx_free_null #define mx_free_null(a) do { free(a); (a) = NULL; } while(0) #undef _mx_cleanup_ #define _mx_cleanup_(x) __attribute__((cleanup(x))) static inline void __mx_free(void *ptr) { free(*(void **)ptr); } static inline void __mx_fclose(FILE **ptr) { if (*ptr) fclose(*ptr); } #undef _mx_cleanup_free_ #define _mx_cleanup_free_ _mx_cleanup_(__mx_free) #undef _mx_cleanup_fclose_ #define _mx_cleanup_fclose_ _mx_cleanup_(__mx_fclose) #undef likely #define likely(x) __builtin_expect((x),1) #undef unlikely #define unlikely(x) __builtin_expect((x),0) #undef mx_streq #define mx_streq(a, b) (strcmp((a), (b)) == 0) #undef mx_streq_nocase #define mx_streq_nocase(a, b) (strcasecmp((a), (b)) == 0) int mx_strbeginswith(char *str, const char *start, char **endptr); int mx_stribeginswith(char *str, const char *start, char **endptr); int mx_strbeginswithany(char *str, char **starts, char **endptr); char *mx_strskipwhitespaces(char *str); int mx_strtobytes(char *str, unsigned long long int *bytes); int mx_strtoseconds(char *str, unsigned long long int *seconds); int mx_strtominutes(char *str, unsigned long long int *minutes); int mx_strtoul(char *str, unsigned long int *to); int mx_strtoull(char *str, unsigned long long int *to); int mx_strtoui(char *str, unsigned int *to); int mx_strtou8(char *str, uint8_t *to); int mx_strtou16(char *str, uint16_t *to); int mx_strtou32(char *str, uint32_t *to); int mx_strtou64(char *str, uint64_t *to); int mx_strtol(char *str, signed long int *to); int mx_strtoll(char *str, signed long long int *to); int mx_strtoi(char *str, signed int *to); int mx_strtoi8(char *str, int8_t *to); int mx_strtoi16(char *str, int16_t *to); int mx_strtoi32(char *str, int32_t *to); int mx_strtoi64(char *str, int64_t *to); char *mx_strdup_forever(char *str); int mx_vasprintf_forever(char **strp, const char *fmt, va_list ap); int mx_asprintf_forever(char **strp, const char *fmt, ...) __attribute__ ((format(printf, 2, 3))); char *mx_hostname(void); char *mx_dirname(char *path); char *mx_dirname_forever(char *path); int mx_dup2_close_new(int oldfd, int newfd); int mx_dup2_close_both(int oldfd, int newfd); int mx_setenv_forever(const char *name, const char *value); int mx_setenvf_forever(const char *name, char *fmt, ...) __attribute__ ((format(printf, 2, 3))); int mx_open_newfile(char *fname); int mx_read_first_line_from_file(char *fname, char **line); int mx_strscan_ull(char **str, unsigned long long int *to); int mx_strscan_ll(char **str, long long int *to); int mx_strscan_proc_pid_stat(char *str, struct proc_pid_stat *pps); int mx_proc_pid_stat(struct proc_pid_stat *pps, pid_t pid); void mx_proc_pid_stat_free(struct proc_pid_stat *pps); int mx_sleep(unsigned int seconds); int mx_sleep_nofail(unsigned int seconds); #ifndef MX_CALLOC_FAIL_WAIT_DEFAULT # define MX_CALLOC_FAIL_WAIT_DEFAULT 1 #endif #define mx_calloc_forever(n, s) mx_calloc_forever_sec((n), (s), MX_CALLOC_FAIL_WAIT_DEFAULT) void *mx_calloc_forever_sec(size_t nmemb, size_t size, unsigned int time); char** mx_strvec_new(void); size_t mx_strvec_length(char **strvec); int mx_strvec_push_str(char ***strvecp, char *str); int mx_strvec_push_strvec(char*** strvecp, char **strvec); char* mx_strvec_to_str(char **strvec); char** mx_strvec_from_str(char *str); void mx_strvec_free(char **strvec); #endif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
You can’t perform that action at this time.