2 * Copyright (C) 2008 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file adu.h Global definitions. */
14 #include <time.h> /* time(), localtime() */
23 #include "gcc-compat.h"
25 /** debug loglevel, gets really noisy */
27 /** still noisy, but won't fill your disk */
29 /** normal, but significant event */
31 /** unexpected event that can be handled */
33 /** unhandled error condition */
35 /** system might be unreliable */
37 /** last message before exit */
40 /** Log messages with lower priority than that will not be compiled in. */
41 #define COMPILE_TIME_LOGLEVEL 0
44 #if DEBUG > COMPILE_TIME_LOGLEVEL
45 #define DEBUG_LOG(f,...) __log(DEBUG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
47 #define DEBUG_LOG(...) do {;} while (0)
50 #if INFO > COMPILE_TIME_LOGLEVEL
51 #define INFO_LOG(f,...) __log(INFO, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
53 #define INFO_LOG(...) do {;} while (0)
56 #if NOTICE > COMPILE_TIME_LOGLEVEL
57 #define NOTICE_LOG(f,...) __log(NOTICE, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
59 #define NOTICE_LOG(...) do {;} while (0)
62 #if WARNING > COMPILE_TIME_LOGLEVEL
63 #define WARNING_LOG(f,...) __log(WARNING, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
65 #define WARNING_LOG(...) do {;} while (0)
68 #if ERROR > COMPILE_TIME_LOGLEVEL
69 #define ERROR_LOG(f,...) __log(ERROR, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
71 #define ERROR_LOG(...) do {;} while (0)
74 #if CRIT > COMPILE_TIME_LOGLEVEL
75 #define CRIT_LOG(f,...) __log(CRIT, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
77 #define CRIT_LOG(...) do {;} while (0)
80 #if EMERG > COMPILE_TIME_LOGLEVEL
81 #define EMERG_LOG(f,...) __log(EMERG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
83 #define EMERG_LOG(...)
88 * Write a log message to a dynamically allocated string.
90 * \param fmt Usual format string.
91 * \param p Result pointer.
94 #define VSPRINTF(fmt, p) \
98 p = adu_malloc(size); \
101 /* Try to print in the allocated space. */ \
103 n = vsnprintf(p, size, fmt, ap); \
105 /* If that worked, return the string. */ \
106 if (n > -1 && n < size) \
108 /* Else try again with more space. */ \
109 if (n > -1) /* glibc 2.1 */ \
110 size = n + 1; /* precisely what is needed */ \
111 else /* glibc 2.0 */ \
112 size *= 2; /* twice the old size */ \
113 p = adu_realloc(p, size); \
117 /** Evaluates to 1 if x < y, to -1 if x > y and to 0 if x == y. */
118 #define NUM_COMPARE(x, y) ((int)((x) < (y)) - (int)((x) > (y)))
120 /** The columns of the directory table. */
121 enum dir_table_columns {
122 /** The name of the directory. */
124 /** The dir count number. */
126 /** The number of the parent directory. */
128 /** The number of bytes of all regular files. */
130 /** The number of all regular files. */
132 /** Number of columns in this table. */
136 /** The columns of the id table. */
137 enum user_table_columns {
138 /** The numer of the directory. */
140 /** The number of bytes of all regular files in this dir owned by this id. */
142 /** The number of files in this dir owned by this id. */
144 /** Number of columns in this table. */
148 enum uid_info_flags {
149 /** Whether this slot of the hash table is used. */
151 /** Whether this uid should be taken into account. */
152 UI_FL_ADMISSIBLE = 2,
159 struct osl_table *table;
163 struct osl_table_description *desc;
171 enum search_uid_flags {
173 CREATE_USER_TABLE = 2,
176 extern uint32_t num_uids;
177 extern struct osl_table *dir_table;
178 extern struct gengetopt_args_info conf;
181 __printf_2_3 void __log(int, const char*, ...);
182 int open_dir_table(int create);
183 void check_signals(void);
184 void close_all_tables(void);
185 char *get_uid_list_name(void);
186 void create_hash_table(unsigned bits);
187 int search_uid(uint32_t uid, enum search_uid_flags flags,
188 struct user_info **ui_ptr);
189 int for_each_admissible_user(int (*func)(struct user_info *, void *),
191 void sort_hash_table(int (*comp)(const void *, const void *));
194 int com_select(void);
197 int com_create(void);