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 <path> | --logfile=<path>\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 <path> | --logfile=<path>\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 <user> | --socket-user=<user> set");
fprintf(fd, " " CGRULE_CGRED_SOCKET_PATH " socket user\n");
fprintf(fd, " -g <group> | --socket-group=<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);
}
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);
}
if (copy) {
vsyslog(LOG_MAKEPRI(logfacility, level), format, cap);
va_end(cap);
- } else
+ } else {
vsyslog(LOG_MAKEPRI(logfacility, level), format, ap);
+ }
}
}
}
/**
- * 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;
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;
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");
timestamp_parent = array_pi.parent_info[i]->timestamp;
if (timestamp_child > timestamp_parent)
continue;
+
return 1;
}
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;
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;
}
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;
}
}
}
/**
- * 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
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;
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;
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;
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) {
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);
}
/**
- * 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
*/
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:
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:
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;
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;
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;
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;
}
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;
}
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;
}
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");
/* 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;
}
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",
} 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;
}
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);
}
/**
* @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;
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);
/* 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;
}
}
/**
- * 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)
}
/**
- * 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)
}
/**
- * 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)
/* 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)
}
/*
- * 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");
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;
}
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);
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, "");
}
/* 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;
}
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;
}
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;
}