From: Kamalesh Babulal Date: Thu, 30 Jun 2022 08:18:46 +0000 (+0530) Subject: daemon/cgruleseng.c: increase the column width to 100 X-Git-Tag: v3.0~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=700251d66b16c48864f72266f32aafb45972d8ae;p=thirdparty%2Flibcgroup.git daemon/cgruleseng.c: increase the column width to 100 100 column width is more comfortable to read over 80 columns, lets increase it. This patch, also introduced/removes empty lines across the file, making it more readable. Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/daemon/cgrulesengd.c b/src/daemon/cgrulesengd.c index 8f85058b..56fe7c01 100644 --- a/src/daemon/cgrulesengd.c +++ b/src/daemon/cgrulesengd.c @@ -96,21 +96,16 @@ static void usage(FILE *fd, const char *msg, ...) fprintf(fd, " options :\n"); fprintf(fd, " -q | --quiet\t\t quiet mode\n"); fprintf(fd, " -v | --verbose\t\t verbose mode\n"); - fprintf(fd, " -f | --logfile=\t write log to "); - fprintf(fd, "file\n"); - fprintf(fd, " -s[facility] | --syslog=[facility]\t write log to "); - fprintf(fd, "syslog\n"); - fprintf(fd, " -n | --nodaemon\t\t don't fork "); - fprintf(fd, "daemon\n"); - fprintf(fd, " -d | --debug\t\t same as -v -v -n"); - fprintf(fd, " -f -\n"); + fprintf(fd, " -f | --logfile=\t write log to file\n"); + fprintf(fd, " -s[facility] | --syslog=[facility]\t write log to syslog\n"); + fprintf(fd, " -n | --nodaemon\t\t don't fork daemon\n"); + fprintf(fd, " -d | --debug\t\t same as -v -v -n -f -\n"); fprintf(fd, " -Q | --nolog\t\t disable logging\n"); fprintf(fd, " -u | --socket-user= set"); fprintf(fd, " " CGRULE_CGRED_SOCKET_PATH " socket user\n"); fprintf(fd, " -g | --socket-group= set"); fprintf(fd, " " CGRULE_CGRED_SOCKET_PATH " socket group\n"); - fprintf(fd, " -h | --help\t\t show this "); - fprintf(fd, "help\n\n"); + fprintf(fd, " -h | --help\t\t show this help\n\n"); va_end(ap); } @@ -142,8 +137,8 @@ void flog_write(int level, const char *format, va_list ap) vfprintf(logfile, format, ap); /* - * Flush the stream's buffer, so the data is readable - * immediately. + * Flush the stream's buffer, so the data + * is readable immediately. */ fflush(logfile); } @@ -152,8 +147,9 @@ void flog_write(int level, const char *format, va_list ap) if (copy) { vsyslog(LOG_MAKEPRI(logfacility, level), format, cap); va_end(cap); - } else + } else { vsyslog(LOG_MAKEPRI(logfacility, level), format, ap); + } } } @@ -175,11 +171,10 @@ void flog(int level, const char *format, ...) } /** - * Libcgroup logging callback. It must translate libcgroup log levels to - * cgrulesengd native (=syslog). + * Libcgroup logging callback. It must translate libcgroup log levels + * to cgrulesengd native (=syslog). */ -void flog_cgroup(void *userdata, int cgroup_level, const char *format, - va_list ap) +void flog_cgroup(void *userdata, int cgroup_level, const char *format, va_list ap) { int level = 0; @@ -227,8 +222,7 @@ static int cgre_store_parent_info(pid_t pid) if (array_pi.index >= array_pi.num_allocation) { int alloc = array_pi.num_allocation + NUM_PER_REALLOCATIOM; - void *new_array = realloc(array_pi.parent_info, - sizeof(info) * alloc); + void *new_array = realloc(array_pi.parent_info, sizeof(info) * alloc); if (!new_array) { flog(LOG_WARNING, "Failed to allocate memory\n"); return 1; @@ -236,6 +230,7 @@ static int cgre_store_parent_info(pid_t pid) array_pi.parent_info = new_array; array_pi.num_allocation = alloc; } + info = calloc(1, sizeof(struct parent_info)); if (!info) { flog(LOG_WARNING, "Failed to allocate memory\n"); @@ -285,6 +280,7 @@ static int cgre_was_parent_changed_when_forking(const struct proc_event *ev) timestamp_parent = array_pi.parent_info[i]->timestamp; if (timestamp_child > timestamp_parent) continue; + return 1; } @@ -317,8 +313,7 @@ static int cgre_store_unchanged_process(pid_t pid, int flags) if (array_unch.index >= array_unch.num_allocation) { int alloc = array_unch.num_allocation + NUM_PER_REALLOCATIOM; - void *new_array = realloc(array_unch.proc, - sizeof(unchanged_pid_t) * alloc); + void *new_array = realloc(array_unch.proc, sizeof(unchanged_pid_t) * alloc); if (!new_array) { flog(LOG_WARNING, "Failed to allocate memory\n"); return 1; @@ -330,8 +325,7 @@ static int cgre_store_unchanged_process(pid_t pid, int flags) array_unch.proc[array_unch.index].flags = flags; array_unch.index++; - flog(LOG_DEBUG, "Store the unchanged process (PID: %d, FLAGS: %d)\n", - pid, flags); + flog(LOG_DEBUG, "Store the unchanged process (PID: %d, FLAGS: %d)\n", pid, flags); return 0; } @@ -345,12 +339,10 @@ static void cgre_remove_unchanged_process(pid_t pid) continue; for (j = i; j < array_unch.index - 1; j++) - memcpy(&array_unch.proc[j], - &array_unch.proc[j + 1], + memcpy(&array_unch.proc[j], &array_unch.proc[j + 1], sizeof(struct unchanged_pid)); array_unch.index--; - flog(LOG_DEBUG, "Remove the unchanged process (PID: %d)\n", - pid); + flog(LOG_DEBUG, "Remove the unchanged process (PID: %d)\n", pid); return; } } @@ -384,9 +376,9 @@ static int cgre_is_unchanged_child(pid_t pid) } /** - * Process an event from the kernel, and determine the correct UID/GID/PID to - * pass to libcgroup. Then, libcgroup will decide the cgroup to move the PID - * to, if any. + * Process an event from the kernel, and determine the correct UID/GID/PID + * to pass to libcgroup. Then, libcgroup will decide the cgroup to move + * the PID to, if any. * @param ev The event to process * @param type The type of event to process (part of ev) * @return 0 on success, > 0 on failure @@ -405,8 +397,8 @@ int cgre_process_event(const struct proc_event *ev, const int type) case PROC_EVENT_UID: case PROC_EVENT_GID: /* - * If the unchanged process, the daemon should not change the - * cgroup of the process. + * If the unchanged process, the daemon should not change + * the cgroup of the process. */ if (cgre_is_unchanged_process(ev->event_data.id.process_pid)) return 0; @@ -416,14 +408,13 @@ int cgre_process_event(const struct proc_event *ev, const int type) ppid = ev->event_data.fork.parent_pid; cpid = ev->event_data.fork.child_pid; if (cgre_is_unchanged_child(ppid)) { - if (cgre_store_unchanged_process(cpid, - CGROUP_DAEMON_UNCHANGE_CHILDREN)) + if (cgre_store_unchanged_process(cpid, CGROUP_DAEMON_UNCHANGE_CHILDREN)) return 1; } /* - * If this process was forked while changing parent's cgroup, - * this process's cgroup also should be changed. + * If this process was forked while changing parent's + * cgroup, this process's cgroup also should be changed. */ if (!cgre_was_parent_changed_when_forking(ev)) return 0; @@ -434,8 +425,8 @@ int cgre_process_event(const struct proc_event *ev, const int type) return 0; case PROC_EVENT_EXEC: /* - * If the unchanged process, the daemon should not change the - * cgroup of the process. + * If the unchanged process, the daemon should not change + * the cgroup of the process. */ if (cgre_is_unchanged_process(ev->event_data.exec.process_pid)) return 0; @@ -462,8 +453,8 @@ int cgre_process_event(const struct proc_event *ev, const int type) return ret; /* - * Now that we have the UID, the GID, and the PID, we can make a call - * to libcgroup to change the cgroup for this PID. + * Now that we have the UID, the GID, and the PID, we can make a + * call to libcgroup to change the cgroup for this PID. */ log_pid = pid; switch (type) { @@ -489,29 +480,23 @@ int cgre_process_event(const struct proc_event *ev, const int type) break; } - ret = cgroup_change_cgroup_flags(euid, egid, procname, pid, - CGFLAG_USECACHE); + ret = cgroup_change_cgroup_flags(euid, egid, procname, pid, CGFLAG_USECACHE); if (ret == ECGOTHER) { /* - * A process finished already but we may have missed changing it, - * make sure to apply to forked children. + * A process finished already but we may have missed + * changing it, make sure to apply to forked children. */ - if (cgroup_get_last_errno() == ESRCH || - cgroup_get_last_errno() == ENOENT) + if (cgroup_get_last_errno() == ESRCH || cgroup_get_last_errno() == ENOENT) ret = cgre_store_parent_info(pid); else ret = 0; } else if (ret) { - flog(LOG_WARNING, - "Cgroup change for PID: %d, UID: %d, GID: %d, ", - log_pid, log_uid, log_gid); - flog(LOG_WARNING, "PROCNAME: %s FAILED! (Error Code: %d)\n", - procname, ret); + flog(LOG_WARNING, "Cgroup change for PID: %d, UID: %d, GID: %d, ", log_pid, + log_uid, log_gid); + flog(LOG_WARNING, "PROCNAME: %s FAILED! (Error Code: %d)\n", procname, ret); } else { - flog(LOG_INFO, - "Cgroup change for PID: %d, UID: %d, GID: %d, ", - log_pid, log_uid, log_gid); - flog(LOG_INFO, "PROCNAME: %s OK\n", procname); + flog(LOG_INFO, "Cgroup change for PID: %d, UID: %d, GID: %d, PROCNAME: %s OK\n", + log_pid, log_uid, log_gid, procname); ret = cgre_store_parent_info(pid); } free(procname); @@ -520,9 +505,9 @@ int cgre_process_event(const struct proc_event *ev, const int type) } /** - * Handle a netlink message. In the event of PROC_EVENT_UID or PROC_EVENT_GID, - * we pass the event along to cgre_process_event for further processing. All - * other events are ignored. + * Handle a netlink message. + * In the event of PROC_EVENT_UID or PROC_EVENT_GID, we pass the event along + * to cgre_process_event for further processing. All other events are ignored. * @param cn_hdr The netlink message * @return 0 on success, > 0 on error */ @@ -538,21 +523,15 @@ static int cgre_handle_msg(struct cn_msg *cn_hdr) ev = (struct proc_event *)cn_hdr->data; switch (ev->what) { case PROC_EVENT_UID: - flog(LOG_DEBUG, - "UID Event: PID = %d, tGID = %d, rUID = %d, eUID = %d\n", - ev->event_data.id.process_pid, - ev->event_data.id.process_tgid, - ev->event_data.id.r.ruid, - ev->event_data.id.e.euid); + flog(LOG_DEBUG, "UID Event: PID = %d, tGID = %d, rUID = %d, eUID = %d\n", + ev->event_data.id.process_pid, ev->event_data.id.process_tgid, + ev->event_data.id.r.ruid, ev->event_data.id.e.euid); ret = cgre_process_event(ev, PROC_EVENT_UID); break; case PROC_EVENT_GID: - flog(LOG_DEBUG, - "GID Event: PID = %d, tGID = %d, rGID = %d, eGID = %d\n", - ev->event_data.id.process_pid, - ev->event_data.id.process_tgid, - ev->event_data.id.r.rgid, - ev->event_data.id.e.egid); + flog(LOG_DEBUG, "GID Event: PID = %d, tGID = %d, rGID = %d, eGID = %d\n", + ev->event_data.id.process_pid, ev->event_data.id.process_tgid, + ev->event_data.id.r.rgid, ev->event_data.id.e.egid); ret = cgre_process_event(ev, PROC_EVENT_GID); break; case PROC_EVENT_FORK: @@ -563,8 +542,7 @@ static int cgre_handle_msg(struct cn_msg *cn_hdr) break; case PROC_EVENT_EXEC: flog(LOG_DEBUG, "EXEC Event: PID = %d, tGID = %d\n", - ev->event_data.exec.process_pid, - ev->event_data.exec.process_tgid); + ev->event_data.exec.process_pid, ev->event_data.exec.process_tgid); ret = cgre_process_event(ev, PROC_EVENT_EXEC); break; default: @@ -585,8 +563,8 @@ static int cgre_receive_netlink_msg(int sk_nl) memset(buff, 0, sizeof(buff)); from_nla_len = sizeof(from_nla); - recv_len = recvfrom(sk_nl, buff, sizeof(buff), 0, - (struct sockaddr *)&from_nla, &from_nla_len); + recv_len = recvfrom(sk_nl, buff, sizeof(buff), 0, (struct sockaddr *)&from_nla, + &from_nla_len); if (recv_len == ENOBUFS) { flog(LOG_ERR, "ERROR: NETLINK BUFFER FULL, MESSAGE DROPPED!\n"); return 0; @@ -600,8 +578,7 @@ static int cgre_receive_netlink_msg(int sk_nl) return 0; } - if (from_nla.nl_groups != CN_IDX_PROC - || from_nla.nl_pid != 0) + if (from_nla.nl_groups != CN_IDX_PROC || from_nla.nl_pid != 0) return 0; nlh = (struct nlmsghdr *)buff; @@ -612,8 +589,7 @@ static int cgre_receive_netlink_msg(int sk_nl) nlh = NLMSG_NEXT(nlh, recv_len); continue; } - if ((nlh->nlmsg_type == NLMSG_ERROR) || - (nlh->nlmsg_type == NLMSG_OVERRUN)) + if ((nlh->nlmsg_type == NLMSG_ERROR) || (nlh->nlmsg_type == NLMSG_OVERRUN)) break; if (cgre_handle_msg(cn_hdr) < 0) return 1; @@ -638,42 +614,33 @@ static void cgre_receive_unix_domain_msg(int sk_unix) caddr_len = sizeof(caddr); fd_client = accept(sk_unix, (struct sockaddr *)&caddr, &caddr_len); if (fd_client < 0) { - flog(LOG_WARNING, "Warning: 'accept' command error: %s\n", - strerror(errno)); + flog(LOG_WARNING, "Warning: 'accept' command error: %s\n", strerror(errno)); return; } if (read(fd_client, &pid, sizeof(pid)) < 0) { - flog(LOG_WARNING, "Warning: 'read' command error: %s\n", - strerror(errno)); + flog(LOG_WARNING, "Warning: 'read' command error: %s\n", strerror(errno)); goto close; } sprintf(path, "/proc/%d", pid); if (stat(path, &buff_stat)) { - flog(LOG_WARNING, - "Warning: there is no such process (PID: %d)\n", pid); + flog(LOG_WARNING, "Warning: there is no such process (PID: %d)\n", pid); goto close; } if (read(fd_client, &flags, sizeof(flags)) < 0) { - flog(LOG_WARNING, "Warning: error reading daemon socket: %s\n", - strerror(errno)); + flog(LOG_WARNING, "Warning: error reading daemon socket: %s\n", strerror(errno)); goto close; } if (flags == CGROUP_DAEMON_CANCEL_UNCHANGE_PROCESS) cgre_remove_unchanged_process(pid); - else - if (cgre_store_unchanged_process(pid, flags)) - goto close; - - if (write(fd_client, CGRULE_SUCCESS_STORE_PID, - sizeof(CGRULE_SUCCESS_STORE_PID)) < 0) { + else if (cgre_store_unchanged_process(pid, flags)) + goto close; - flog(LOG_WARNING, - "Warning: cannot write to daemon socket: %s\n", - strerror(errno)); + if (write(fd_client, CGRULE_SUCCESS_STORE_PID, sizeof(CGRULE_SUCCESS_STORE_PID)) < 0) { + flog(LOG_WARNING, "Warning: cannot write to daemon socket: %s\n", strerror(errno)); goto close; } @@ -695,15 +662,13 @@ static int cgre_create_netlink_socket_process_msg(void) int rc = -1; /* - * Create an endpoint for communication. Use the kernel user - * interface device (PF_NETLINK) which is a datagram oriented - * service (SOCK_DGRAM). The protocol used is the connector - * protocol (NETLINK_CONNECTOR) + * Create an endpoint for communication. Use the kernel user interface + * device (PF_NETLINK) which is a datagram oriented service (SOCK_DGRAM). + * The protocol used is the connector protocol (NETLINK_CONNECTOR) */ sk_nl = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR); if (sk_nl == -1) { - flog(LOG_ERR, "Error: error opening netlink socket: %s\n", - strerror(errno)); + flog(LOG_ERR, "Error: error opening netlink socket: %s\n", strerror(errno)); return rc; } @@ -713,8 +678,7 @@ static int cgre_create_netlink_socket_process_msg(void) my_nla.nl_pad = 0; if (bind(sk_nl, (struct sockaddr *)&my_nla, sizeof(my_nla)) < 0) { - flog(LOG_ERR, "Error: error binding netlink socket: %s\n", - strerror(errno)); + flog(LOG_ERR, "Error: error binding netlink socket: %s\n", strerror(errno)); goto close_and_exit; } @@ -738,12 +702,12 @@ static int cgre_create_netlink_socket_process_msg(void) cn_hdr->seq = 0; cn_hdr->ack = 0; cn_hdr->len = sizeof(enum proc_cn_mcast_op); - flog(LOG_DEBUG, "Sending netlink message len=%d, cn_msg len=%d\n", - nl_hdr->nlmsg_len, (int) sizeof(struct cn_msg)); + flog(LOG_DEBUG, "Sending netlink message len=%d, cn_msg len=%d\n", nl_hdr->nlmsg_len, + (int) sizeof(struct cn_msg)); if (send(sk_nl, nl_hdr, nl_hdr->nlmsg_len, 0) != nl_hdr->nlmsg_len) { - flog(LOG_ERR, "Error: failed to send netlink message "); - flog(LOG_ERR, "(mcast ctl op): %s\n", strerror(errno)); + flog(LOG_ERR, "Error: failed to send netlink message (mcast ctl op): %s\n", + strerror(errno)); goto close_and_exit; } flog(LOG_DEBUG, "Message sent\n"); @@ -751,8 +715,7 @@ static int cgre_create_netlink_socket_process_msg(void) /* Setup Unix domain socket. */ sk_unix = socket(PF_UNIX, SOCK_STREAM, 0); if (sk_unix < 0) { - flog(LOG_ERR, "Error creating UNIX socket: %s\n", - strerror(errno)); + flog(LOG_ERR, "Error creating UNIX socket: %s\n", strerror(errno)); goto close_and_exit; } @@ -763,27 +726,26 @@ static int cgre_create_netlink_socket_process_msg(void) if (bind(sk_unix, (struct sockaddr *)&saddr, sizeof(saddr.sun_family) + strlen(CGRULE_CGRED_SOCKET_PATH)) < 0) { - flog(LOG_ERR, "Error binding UNIX socket %s: %s\n", - CGRULE_CGRED_SOCKET_PATH, strerror(errno)); + flog(LOG_ERR, "Error binding UNIX socket %s: %s\n", CGRULE_CGRED_SOCKET_PATH, + strerror(errno)); goto close_and_exit; } if (listen(sk_unix, 1) < 0) { - flog(LOG_ERR, "Error listening on UNIX socket %s: %s\n", - CGRULE_CGRED_SOCKET_PATH, strerror(errno)); + flog(LOG_ERR, "Error listening on UNIX socket %s: %s\n", CGRULE_CGRED_SOCKET_PATH, + strerror(errno)); goto close_and_exit; } /* change the owner */ if (chown(CGRULE_CGRED_SOCKET_PATH, socket_user, socket_group) < 0) { - flog(LOG_ERR, "Error changing %s socket owner: %s\n", - CGRULE_CGRED_SOCKET_PATH, strerror(errno)); + flog(LOG_ERR, "Error changing %s socket owner: %s\n", CGRULE_CGRED_SOCKET_PATH, + strerror(errno)); goto close_and_exit; } - flog(LOG_DEBUG, "Socket %s owner successfully set to %d:%d\n", - CGRULE_CGRED_SOCKET_PATH, (int) socket_user, - (int) socket_group); + flog(LOG_DEBUG, "Socket %s owner successfully set to %d:%d\n", CGRULE_CGRED_SOCKET_PATH, + (int) socket_user, (int) socket_group); if (chmod(CGRULE_CGRED_SOCKET_PATH, 0660) < 0) { flog(LOG_ERR, "Error changing %s socket permissions: %s\n", @@ -864,10 +826,8 @@ static void cgre_start_log(const char *logp, int logf, int logv) } else { logfile = fopen(logp, "a"); if (!logfile) { - fprintf(stderr, "Failed to open log file %s,", - logp); - fprintf(stderr, - " error: %s. Continuing anyway.\n", + fprintf(stderr, "Failed to open log file %s,", logp); + fprintf(stderr, " error: %s. Continuing anyway.\n", strerror(errno)); logfile = stdout; } @@ -895,8 +855,8 @@ static void cgre_start_log(const char *logp, int logf, int logv) tm = time(0); flog(LOG_DEBUG, "Current time: %s\n", ctime(&tm)); - flog(LOG_DEBUG, "Opened log file: %s, log facility: %d,log level: %d\n", - logp, logfacility, loglevel); + flog(LOG_DEBUG, "Opened log file: %s, log facility: %d,log level: %d\n", logp, logfacility, + loglevel); } /** @@ -909,8 +869,7 @@ static void cgre_start_log(const char *logp, int logf, int logv) * @param logv Log verbosity, 1 is the default, 0 = no logging, 5 = everything * @return 0 on success, > 0 on error */ -int cgre_start_daemon(const char *logp, const int logf, - const unsigned char daemon, const int logv) +int cgre_start_daemon(const char *logp, const int logf, const unsigned char daemon, const int logv) { /* PID returned from the fork() */ pid_t pid; @@ -920,12 +879,11 @@ int cgre_start_daemon(const char *logp, const int logf, pid = fork(); if (pid < 0) { openlog("CGRE", LOG_CONS, LOG_DAEMON|LOG_WARNING); - syslog(LOG_DAEMON|LOG_WARNING, - "Failed to fork, error: %s", strerror(errno)); + syslog(LOG_DAEMON|LOG_WARNING, "Failed to fork, error: %s", + strerror(errno)); closelog(); - fprintf(stderr, "Failed to fork(), %s\n", - strerror(errno)); + fprintf(stderr, "Failed to fork(), %s\n", strerror(errno)); return 1; } else if (pid > 0) { exit(EXIT_SUCCESS); @@ -945,15 +903,13 @@ int cgre_start_daemon(const char *logp, const int logf, /* Get a new SID for the child. */ if (setsid() < 0) { - flog(LOG_ERR, "Failed to get a new SID, error: %s\n", - strerror(errno)); + flog(LOG_ERR, "Failed to get a new SID, error: %s\n", strerror(errno)); return 2; } /* Change to the root directory. */ if (chdir("/") < 0) { - flog(LOG_ERR, "Failed to chdir to /, error: %s\n", - strerror(errno)); + flog(LOG_ERR, "Failed to chdir to /, error: %s\n", strerror(errno)); return 3; } @@ -970,8 +926,8 @@ int cgre_start_daemon(const char *logp, const int logf, } /** - * Catch the SIGUSR2 signal and reload the rules configuration. This function - * makes use of the logfile and flog() to print the new rules. + * Catch the SIGUSR2 signal and reload the rules configuration. + * This function makes use of the logfile and flog() to print the new rules. * @param signum The signal that we caught (always SIGUSR2) */ void cgre_flash_rules(int signum) @@ -998,8 +954,8 @@ void cgre_flash_rules(int signum) } /** - * Catch the SIGUSR1 signal and reload the rules configuration. This function - * makes use of the logfile and flog() to print the new rules. + * Catch the SIGUSR1 signal and reload the rules configuration. + * This function makes use of the logfile and flog() to print the new rules. * @param signum The signal that we caught (always SIGUSR1) */ void cgre_flash_templates(int signum) @@ -1017,8 +973,8 @@ void cgre_flash_templates(int signum) } /** - * Catch the SIGTERM and SIGINT signals so that we can exit gracefully. Before - * exiting, this function makes use of the logfile and flog(). + * Catch the SIGTERM and SIGINT signals so that we can exit gracefully. + * Before exiting, this function makes use of the logfile and flog(). * @param signum The signal that we caught (SIGTERM, SIGINT) */ void cgre_catch_term(int signum) @@ -1026,8 +982,7 @@ void cgre_catch_term(int signum) /* Current time */ time_t tm = time(0); - flog(LOG_INFO, "Stopped CGroup Rules Engine Daemon at %s\n", - ctime(&tm)); + flog(LOG_INFO, "Stopped CGroup Rules Engine Daemon at %s\n", ctime(&tm)); /* Close the log file, if we opened one */ if (logfile && logfile != stdout) @@ -1127,8 +1082,8 @@ int main(int argc, char *argv[]) } /* - * Check environment variable CGROUP_LOGLEVEL. If it's set to DEBUG, - * set appropriate verbosity level. + * Check environment variable CGROUP_LOGLEVEL. If it's set to + * DEBUG, set appropriate verbosity level. */ char *level_str = getenv("CGROUP_LOGLEVEL"); @@ -1172,9 +1127,7 @@ int main(int argc, char *argv[]) if (optarg) { facility = cgre_parse_syslog_facility(optarg); if (facility == 0) { - fprintf(stderr, - "Unknown syslog facility: %s\n", - optarg); + fprintf(stderr, "Unknown syslog facility: %s\n", optarg); ret = 2; goto finished; } @@ -1201,8 +1154,7 @@ int main(int argc, char *argv[]) goto finished; } socket_user = pw->pw_uid; - flog(LOG_DEBUG, "Using socket user %s id %d\n", - optarg, (int)socket_user); + flog(LOG_DEBUG, "Using socket user %s id %d\n", optarg, (int)socket_user); break; case 'g': /* --socket-group */ gr = getgrnam(optarg); @@ -1212,8 +1164,8 @@ int main(int argc, char *argv[]) goto finished; } socket_group = gr->gr_gid; - flog(LOG_DEBUG, "Using socket group %s id %d\n", - optarg, (int)socket_group); + flog(LOG_DEBUG, "Using socket group %s id %d\n", optarg, + (int)socket_group); break; default: usage(stderr, ""); @@ -1231,31 +1183,25 @@ int main(int argc, char *argv[]) } /* Ask libcgroup to load the configuration rules. */ - ret = cgroup_string_list_init(&template_files, - CGCONFIG_CONF_FILES_LIST_MINIMUM_SIZE); + ret = cgroup_string_list_init(&template_files, CGCONFIG_CONF_FILES_LIST_MINIMUM_SIZE); if (ret) { - fprintf(stderr, "%s: cannot init file list, out of memory?\n", - argv[0]); + fprintf(stderr, "%s: cannot init file list, out of memory?\n", argv[0]); goto finished_without_temp_files; } /* first add CGCONFIG_CONF_FILE into file list */ ret = cgroup_string_list_add_item(&template_files, CGCONFIG_CONF_FILE); if (ret) { - fprintf(stderr, - "%s: cannot add file to list, out of memory?\n", - argv[0]); + fprintf(stderr, "%s: cannot add file to list, out of memory?\n", argv[0]); goto finished; } /* then read CGCONFIG_CONF_DIR directory for additional config files */ - cgroup_string_list_add_directory(&template_files, CGCONFIG_CONF_DIR, - argv[0]); + cgroup_string_list_add_directory(&template_files, CGCONFIG_CONF_DIR, argv[0]); ret = cgroup_init_rules_cache(); if (ret != 0) { fprintf(stderr, "Error: libcgroup failed to initialize rules"); - fprintf(stderr, "cache from %s. %s\n", - CGRULES_CONF_FILE, cgroup_strerror(ret)); + fprintf(stderr, "cache from %s. %s\n", CGRULES_CONF_FILE, cgroup_strerror(ret)); goto finished; } @@ -1263,37 +1209,31 @@ int main(int argc, char *argv[]) cgroup_templates_cache_set_source_files(&template_files); ret = cgroup_load_templates_cache_from_files(&fileindex); if (ret != 0) { - if (fileindex < 0) { - fprintf(stderr, "Error: Template source files "); - fprintf(stderr, "have not been set\n"); - } else { - fprintf(stderr, "Error: Failed to initialize template"); - fprintf(stderr, "rules from %s. ", - template_files.items[fileindex]); - fprintf(stderr, "%s\n", cgroup_strerror(-ret)); - } + if (fileindex < 0) + fprintf(stderr, "Error: Template source files have not been set\n"); + else + fprintf(stderr, "Error: Failed to initialize template rules from %s.%s\n", + template_files.items[fileindex], cgroup_strerror(-ret)); goto finished; } /* Now, start the daemon. */ ret = cgre_start_daemon(logp, facility, daemon, verbosity); if (ret < 0) { - fprintf(stderr, "Error: Failed to launch the daemon, %s\n", - cgroup_strerror(ret)); + fprintf(stderr, "Error: Failed to launch the daemon, %s\n", cgroup_strerror(ret)); goto finished; } /* - * Set up the signal handler to reload the cached rules upon reception - * of a SIGUSR2 signal. + * Set up the signal handler to reload the cached rules upon + * reception of a SIGUSR2 signal. */ memset(&sa, 0, sizeof(sa)); sa.sa_handler = &cgre_flash_rules; sigemptyset(&sa.sa_mask); ret = sigaction(SIGUSR2, &sa, NULL); if (ret) { - flog(LOG_ERR, - "Failed to set up signal handler for SIGUSR2. Error: %s\n", + flog(LOG_ERR, "Failed to set up signal handler for SIGUSR2. Error: %s\n", strerror(errno)); goto finished; } @@ -1305,23 +1245,20 @@ int main(int argc, char *argv[]) sa.sa_handler = &cgre_flash_templates; ret = sigaction(SIGUSR1, &sa, NULL); if (ret) { - flog(LOG_ERR, - "Failed to set up signal handler for SIGUSR1. Error: %s\n", + flog(LOG_ERR, "Failed to set up signal handler for SIGUSR1. Error: %s\n", strerror(errno)); goto finished; } /* - * Set up the signal handler to catch SIGINT and SIGTERM so that we - * can exit gracefully. + * Set up the signal handler to catch SIGINT and SIGTERM so that + * we can exit gracefully */ sa.sa_handler = &cgre_catch_term; ret = sigaction(SIGINT, &sa, NULL); ret |= sigaction(SIGTERM, &sa, NULL); if (ret) { - flog(LOG_ERR, - "Failed to set up the signal handler. Error: %s\n", - strerror(errno)); + flog(LOG_ERR, "Failed to set up the signal handler. Error: %s\n", strerror(errno)); goto finished; }