]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: startup: use global progname variable
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Thu, 21 Nov 2024 16:24:37 +0000 (17:24 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 21 Nov 2024 18:55:21 +0000 (19:55 +0100)
Let's store progname in the global variable, as it is handy to use it in
different parts of code to format messages sent to stdout.

This reduces the number of arguments, which we should pass to some functions.

include/haproxy/global.h
include/haproxy/linuxcap.h
src/haproxy.c
src/linuxcap.c

index f5c2628d1e70182101ffb98d0fb1fb2b06064fd6..eb1fc6ec24625a412f7add193ee9da42cfa5fc97 100644 (file)
@@ -50,6 +50,7 @@ extern int atexit_flag;
 extern unsigned char boot_seed[20];  // per-boot random seed (160 bits initially)
 extern THREAD_LOCAL struct buffer trash;
 extern char **init_env;
+extern char *progname;
 
 struct proxy;
 struct server;
index 44c6074b2344b41518943352bd8ae3f6f38266bf..c4da7f3e219ab41b18e444b6cf4b518a5f631167 100644 (file)
@@ -22,6 +22,6 @@ static inline int capget(cap_user_header_t hdrp, const cap_user_data_t datap)
 }
 int prepare_caps_for_setuid(int from_uid, int to_uid);
 int finalize_caps_after_setuid(int from_uid, int to_uid);
-int prepare_caps_from_permitted_set(int from_uid, int to_uid, const char *progname);
+int prepare_caps_from_permitted_set(int from_uid, int to_uid);
 
 #endif /* _HAPROXY_LINUXCAP_H */
index 6079b9d1b7ca540f88159c436c3b798b239a09c8..f551a2a17997883521913f784719ee3594ba6e8d 100644 (file)
@@ -229,7 +229,7 @@ int connected_peers = 0; /* number of connected peers (verified ones) */
 int arg_mode = 0;      /* MODE_DEBUG etc as passed on command line ... */
 char *change_dir = NULL; /* set when -C is passed */
 char *check_condition = NULL; /* check condition passed to -cc */
-char *progname;
+char *progname = NULL; /* HAProxy binary's name */
 
 /* Here we store information about the pids of the processes we may pause
  * or kill. We will send them a signal every 10 ms until we can bind to all
@@ -1169,7 +1169,7 @@ next_dir_entry:
  * frees in its stack the memory allocated for config files content, if it has
  * encountered an error.
  */
-static int load_cfg(char *progname)
+static int load_cfg()
 {
        struct cfgfile *cfg, *cfg_tmp;
 
@@ -1197,7 +1197,7 @@ static int load_cfg(char *progname)
  * Otherwise, it returns an err_code, which may contain 0 (OK) or ERR_WARN,
  * ERR_ALERT.
  */
-static int read_cfg(char *progname)
+static int read_cfg()
 {
        char *env_cfgfiles = NULL;
        struct cfgfile *cfg;
@@ -1465,7 +1465,7 @@ static void ha_random_boot(char *const *argv)
  * configuration. Makes process to exit with 0, if the condition is true, with
  * 1, if the condition is false or with 2, if parse_line encounters an error.
  */
-static void do_check_condition(char *progname)
+static void do_check_condition()
 {
        int result;
        uint32_t err;
@@ -1603,8 +1603,6 @@ static void init_args(int argc, char **argv)
 {
        char *err_msg = NULL;
 
-       progname = global.log_tag.area;
-
        /* pre-fill in the global tuning options before we let the cmdline
         * change them.
         */
@@ -2333,7 +2331,7 @@ static void step_init_1()
 
        /* Do check_condition, if we started with -cc, and exit. */
        if (global.mode & MODE_CHECK_CONDITION)
-               do_check_condition(progname);
+               do_check_condition();
 
        if (change_dir && chdir(change_dir) < 0) {
                ha_alert("Could not change to directory %s : %s\n", change_dir, strerror(errno));
@@ -2937,7 +2935,7 @@ static void step_init_3(void)
         * binding to privileged ports.
         */
        if (!master)
-           prepare_caps_from_permitted_set(geteuid(), global.uid, progname);
+           prepare_caps_from_permitted_set(geteuid(), global.uid);
 #endif
 }
 
@@ -3098,7 +3096,7 @@ static void read_cfg_in_discovery_mode(int argc, char **argv)
        global.mode |= MODE_DISCOVERY;
 
        usermsgs_clr("config");
-       if (load_cfg(progname) < 0) {
+       if (load_cfg() < 0) {
                if (getenv("HAPROXY_MWORKER_REEXEC") != NULL) {
                        ha_warning("Master failed to load new configuration and "
                                   "can't start a new worker. Already running worker "
@@ -3114,7 +3112,7 @@ static void read_cfg_in_discovery_mode(int argc, char **argv)
                        exit(1);
        }
 
-       if (read_cfg(progname) < 0) {
+       if (read_cfg() < 0) {
                list_for_each_entry_safe(cfg, cfg_tmp, &cfg_cfgfiles, list) {
                        ha_free(&cfg->content);
                        ha_free(&cfg->filename);
@@ -3363,6 +3361,7 @@ void deinit(void)
                }
                free(init_env);
        }
+       free(progname);
 
 } /* end deinit() */
 
@@ -3829,7 +3828,7 @@ int main(int argc, char **argv)
                        setenv("HAPROXY_MWORKER", "1", 1);
                }
                non_global_section_parsed = 0;
-               if (read_cfg(progname) < 0) {
+               if (read_cfg() < 0) {
                        list_for_each_entry_safe(cfg, cfg_tmp, &cfg_cfgfiles, list) {
                                ha_free(&cfg->content);
                                ha_free(&cfg->filename);
index 523c0d22eaa70146ac8372eaebd2c43a9f04add7..90072d2aa9c7d907f9b6160d09a225faca04a7e5 100644 (file)
@@ -80,7 +80,7 @@ static uint32_t caplist;
  * LSTCHK_NETADM/LSTCHK_SYSADM is presented in global.last_checks and some
  * failures are encountered.
  */
-int prepare_caps_from_permitted_set(int from_uid, int to_uid, const char *progname)
+int prepare_caps_from_permitted_set(int from_uid, int to_uid)
 {
        /* _LINUX_CAPABILITY_U32S_1 = 1 and corresponds to version 1, which is three
         * 32-bit integers set. So kernel in capset()/capget() will copy_from/to_user