int main(int argc, char *argv[]) { pid_t pid; sd_journal_print(LOG_DEBUG, "Hi, I am a Screamer and I will make some mess in your Journal log."); sd_journal_print(LOG_NOTICE, "Let me note that you can see various message priorities in Journal and you can filter them."); sd_journal_print(LOG_ERR, "While previous messages are mostly informational, this one reports some error that happend in your system."); sd_journal_print(LOG_ALERT, "Error and Alert get same color, but the latter is much more severe."); sd_journal_send("MESSAGE=You may find some interesting details about logged messages in stored fields. Try to list all fields of messages from process %lu.", (unsigned long) getpid(), "PRIORITY=%i", LOG_NOTICE, "HOME=%s", getenv("HOME"), NULL); // pid = fork(); // if (pid == 0) { // sleep(5); // fprintf(stderr, L_ERROR "No! It's not true! That's impossible!!!\n"); // sleep(1); // return 0; // } else if (pid > 0) { // fprintf(stderr, L_NOTICE "Luke, I am your father!\n"); // } else { // return errno; // } sleep(2); return 0; }
std::string HmiService::Show(const std::string &unit) { if (0 == unit.compare(0, 16, "PowerOff.service")) { sd_journal_print(LOG_DEBUG, "HmiService::Show() - %s (match)\n", unit.c_str()); std::string path = gSystemdSession->StartUnit(unit, "replace"); } else { sd_journal_print(LOG_DEBUG, "HmiService::Show() - %s\n", unit.c_str()); for (int count = 0; count < gdp_surfaces_num; count++) { if (0 == unit.compare(gdp_surfaces[count].unit)) { if (ILM_TRUE == gdp_surfaces[count].created) { extern void surface_control(const int index); // bring gdp_surfaces[count].id_surface to front surface_control(count); sd_journal_print(LOG_DEBUG, "HmiService::Show() - %s surface (%d) exists.\n", unit.c_str(), gdp_surfaces[count].id_surface); } else { // request systemd to start the unit std::string path = gSystemdSession->StartUnit(unit, "replace"); sd_journal_print(LOG_DEBUG, "systemd(session)::StartUnit() - %s\n", path.c_str()); } break; // for-loop } else { sd_journal_print(LOG_DEBUG, "DEBUG: compare \"%s\" with \"%s\"", unit.c_str(), gdp_surfaces[count].unit.c_str()); } } // for-loop } return "Show unit \"" + unit + "\"!"; }
/** * pk_offline_update_write_results: **/ static void pk_offline_update_write_results (PkResults *results) { _cleanup_error_free_ GError *error = NULL; sd_journal_print (LOG_INFO, "writing actual results"); if (!pk_offline_auth_set_results (results, &error)) sd_journal_print (LOG_WARNING, "%s", error->message); }
static int ki_sd_journal_print(sip_msg_t* msg, str* slev, str* stxt) { int ilev; /* one of LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, * LOG_NOTICE, LOG_INFO, LOG_DEBUG, as defined in syslog.h, see syslog(3) */ ilev = LOG_DEBUG; if(slev->len==9 && strncasecmp(slev->s, "LOG_EMERG", slev->len)==0) { ilev = LOG_EMERG; } else if(slev->len==9 && strncasecmp(slev->s, "LOG_ALERT", slev->len)==0) { ilev = LOG_ALERT; } else if(slev->len==8 && strncasecmp(slev->s, "LOG_CRIT", slev->len)==0) { ilev = LOG_CRIT; } else if(slev->len==7 && strncasecmp(slev->s, "LOG_ERR", slev->len)==0) { ilev = LOG_ERR; } else if(slev->len==11 && strncasecmp(slev->s, "LOG_WARNING", slev->len)==0) { ilev = LOG_WARNING; } else if(slev->len==10 && strncasecmp(slev->s, "LOG_NOTICE", slev->len)==0) { ilev = LOG_NOTICE; } else if(slev->len==8 && strncasecmp(slev->s, "LOG_INFO", slev->len)==0) { ilev = LOG_INFO; } sd_journal_print(ilev, "%.*s", stxt->len, stxt->s); return 1; }
static void fusermount_cleanup (const char *mountpoint) { g_autoptr(GError) tmp_error = NULL; const char *fusermount_argv[] = { "fusermount", "-u", mountpoint, NULL}; int estatus; if (!g_spawn_sync (NULL, (char**)fusermount_argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &estatus, &tmp_error)) { g_prefix_error (&tmp_error, "Executing fusermount: "); goto out; } if (!g_spawn_check_exit_status (estatus, &tmp_error)) { g_prefix_error (&tmp_error, "Executing fusermount: "); goto out; } out: /* We don't want a failure to unmount to be fatal, so all we do here * is log. Though in practice what we *really* want is for the * fusermount to be in the bwrap namespace, and hence tied by the * kernel to the lifecycle of the container. This would require * special casing for somehow doing FUSE mounts in bwrap. Which * would be hard because NO_NEW_PRIVS turns off the setuid bits for * fuse. */ if (tmp_error) sd_journal_print (LOG_WARNING, "%s", tmp_error->message); }
static void *relay(void *arg) { char message[MAX_MSG_LEN]; char *off; struct pollfd pfd; struct stream_params *params = (struct stream_params *) arg; ssize_t len; int priority; pthread_cleanup_push(cleanup, arg); if (0 != pthread_sigmask(SIG_BLOCK, ¶ms->mask, NULL)) goto end; pfd.fd = params->fd; pfd.events = POLLIN | POLLERR; do { pfd.revents = 0; if (1 != poll(&pfd, 1, -1)) break; if (0 != (POLLERR & pfd.revents)) break; len = recv(pfd.fd, (void *) message, sizeof(message) - 1, 0); if (0 >= len) break; message[len] = '\0'; /* if the message begins with <%d> (one of the SD_* constants), extract * the priority and strip it */ if (0 != params->level_prefix) { priority = params->priority; off = message; } else { off = strchr(message, '>'); if (NULL == off) { priority = params->priority; off = message; } else { priority = (off - 1)[0] - '0'; ++off; } } if (0 != sd_journal_print(priority, "%s: %s", params->identifier, off)) break; } while (1); end: pthread_cleanup_pop(1); pthread_exit(NULL); }
/** * pk_offline_update_set_plymouth_mode: **/ static void pk_offline_update_set_plymouth_mode (const gchar *mode) { _cleanup_error_free_ GError *error = NULL; _cleanup_free_ gchar *cmdline = NULL; /* allow testing without sending commands to plymouth */ if (g_getenv ("PK_OFFLINE_UPDATE_TEST") != NULL) return; cmdline = g_strdup_printf ("plymouth change-mode --%s", mode); if (!g_spawn_command_line_async (cmdline, &error)) { sd_journal_print (LOG_WARNING, "failed to change mode for splash: %s", error->message); } else { sd_journal_print (LOG_INFO, "sent mode to plymouth '%s'", mode); } }
/** * pk_offline_update_write_error: **/ static void pk_offline_update_write_error (const GError *error) { _cleanup_error_free_ GError *error_local = NULL; _cleanup_object_unref_ PkError *pk_error = NULL; _cleanup_object_unref_ PkResults *results = NULL; sd_journal_print (LOG_INFO, "writing failed results"); results = pk_results_new (); pk_results_set_exit_code (results, PK_EXIT_ENUM_FAILED); pk_error = pk_error_new (); g_object_set (pk_error, "code", PK_ERROR_ENUM_FAILED_INITIALIZATION, "details", error->message, NULL); pk_results_set_error_code (results, pk_error); if (!pk_offline_auth_set_results (results, &error_local)) sd_journal_print (LOG_WARNING, "%s", error_local->message); }
int sd_journal_perror(const char *message) { char fmt[MAX_FMT_LEN]; int len; char *err; g_assert(0 != errno); err = strerror(errno); if (NULL == err) return -EINVAL; if (NULL == message) return sd_journal_print(LOG_ERR, err); len = snprintf(fmt, sizeof(fmt), "%s: %%s", message); if ((0 >= len) || (sizeof(fmt) <= len)) return -EINVAL; return sd_journal_print(LOG_ERR, fmt, err); }
/** * pk_offline_update_write_dummy_results: * * If the transaction crashes, the kernel oopses or we loose power * during the transaction then we never get a chance to write the actual * transaction success / failure file. * * Write a dummy file so at least the user gets notified that something * bad happened. **/ static void pk_offline_update_write_dummy_results (gchar **package_ids) { _cleanup_error_free_ GError *error = NULL; _cleanup_object_unref_ PkError *pk_error = NULL; _cleanup_object_unref_ PkResults *results = NULL; sd_journal_print (LOG_INFO, "writing dummy results"); results = pk_results_new (); pk_results_set_exit_code (results, PK_EXIT_ENUM_FAILED); pk_error = pk_error_new (); g_object_set (pk_error, "code", PK_ERROR_ENUM_FAILED_INITIALIZATION, "details", "The transaction did not complete", NULL); pk_results_set_error_code (results, pk_error); if (!pk_offline_auth_set_results (results, &error)) sd_journal_print (LOG_WARNING, "%s", error->message); /* ensure this is written to disk */ sync (); }
/** * pk_offline_update_power_off: **/ static void pk_offline_update_power_off (void) { _cleanup_error_free_ GError *error = NULL; _cleanup_object_unref_ GDBusConnection *connection = NULL; _cleanup_variant_unref_ GVariant *val = NULL; /* reboot using systemd */ sd_journal_print (LOG_INFO, "shutting down"); pk_offline_update_set_plymouth_mode ("shutdown"); /* TRANSLATORS: we've finished doing offline updates */ pk_offline_update_set_plymouth_msg (_("Shutting down after installing updates…")); connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); if (connection == NULL) { sd_journal_print (LOG_WARNING, "Failed to get system bus connection: %s", error->message); return; } val = g_dbus_connection_call_sync (connection, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "PowerOff", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (val == NULL) { sd_journal_print (LOG_WARNING, "Failed to power off: %s", error->message); return; } }
void log_error(const char *file_name, const char *func, const char *call, int line, int error) { /* * Generic error logging function. * * Propagating the file that the error originated from, the function that * the error was called in, the function call that was the cause of the * error and the line number at which that error occured. * */ sd_journal_print(LOG_ERR, "ERROR :: FILE: %s FUNC: %s CALL: %s LINE: %d MSG: %s", file_name, func, call, line, strerror(error)); }
void _lc_core_log_systemd(int lpriority, const char *format, ...) { va_list arglist; char obuf[LC_LOG_MSG_MAX_SIZE]; int n; int priority; /* Return on MASKed log priorities */ priority = LOG_PRI(lpriority); va_start(arglist, format); n = 0; n += vsnprintf(obuf+n, LC_LOG_MSG_MAX_SIZE - n, format, arglist); va_end(arglist); sd_journal_print(priority, "%.*s", n, obuf); }
/* wrapper for inet_ntop function */ const char* Inet_ntop (int family, const void *addrptr, char *strptr, size_t len) { const char* ptr; if (strptr == NULL) { sd_journal_perror ("NULL destination pointer."); return NULL; } ptr = inet_ntop (family, addrptr, strptr, len); if (ptr == NULL) sd_journal_print (LOG_DEBUG, "inet_ntop returned NULL."); return ptr; /* may return NULL */ }
/** * pk_offline_update_set_plymouth_percentage: **/ static void pk_offline_update_set_plymouth_percentage (guint percentage) { _cleanup_error_free_ GError *error = NULL; _cleanup_free_ gchar *cmdline = NULL; /* allow testing without sending commands to plymouth */ if (g_getenv ("PK_OFFLINE_UPDATE_TEST") != NULL) return; cmdline = g_strdup_printf ("plymouth system-update --progress=%i", percentage); if (!g_spawn_command_line_async (cmdline, &error)) { sd_journal_print (LOG_WARNING, "failed to set percentage for splash: %s", error->message); } }
void rpmostree_bwrap_unref (RpmOstreeBwrap *bwrap) { bwrap->refcount--; if (bwrap->refcount > 0) return; if (bwrap->rofiles_mnt) { g_autoptr(GError) tmp_error = NULL; const char *fusermount_argv[] = { "fusermount", "-u", bwrap->rofiles_mnt, NULL}; int estatus; if (!g_spawn_sync (NULL, (char**)fusermount_argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &estatus, &tmp_error)) { g_prefix_error (&tmp_error, "Executing fusermount: "); goto out; } if (!g_spawn_check_exit_status (estatus, &tmp_error)) { g_prefix_error (&tmp_error, "Executing fusermount: "); goto out; } (void) unlinkat (AT_FDCWD, bwrap->rofiles_mnt, AT_REMOVEDIR); out: /* We don't want a failure to unmount to be fatal, so all we do here * is log. Though in practice what we *really* want is for the * fusermount to be in the bwrap namespace, and hence tied by the * kernel to the lifecycle of the container. This would require * special casing for somehow doing FUSE mounts in bwrap. Which * would be hard because NO_NEW_PRIVS turns off the setuid bits for * fuse. */ if (tmp_error) sd_journal_print (LOG_WARNING, "%s", tmp_error->message); } g_ptr_array_unref (bwrap->argv); g_free (bwrap->rofiles_mnt); g_free (bwrap); }
int main(int argc, char *argv[]) { std::string id_wanted; std::string value; char *argv0; bool newline = false; ARGBEGIN { case 'n': newline = true; break; } ARGEND // this prevents us from going on if we don't know what password if(argv == NULL || *argv == NULL) exit(EXIT_FAILURE); id_wanted = std::string(*argv); try { value = get_password(id_wanted); } catch(std::system_error& e) { errno = e.code().value(); sd_journal_perror("Unable to read key"); exit(EXIT_FAILURE); } catch(std::runtime_error& e) { sd_journal_print(LOG_INFO, e.what()); exit(EXIT_FAILURE); } std::cout << value; if(newline) std::cout << "\n"; exit(EXIT_SUCCESS); }
void JournaldLogHandler::log(const qi::LogLevel verb, const char* category, const char* msg, const char* file, const char* fct, const int line) { // systemd uses the log level defined by syslog. // Here is how we mix both. // LOG_EMERG(0) LogLevel_Fatal(1) // LOG_ALERT(1) // LOG_CRIT(2) // LOG_ERR(3) LogLevel_Error(2) // LOG_WARNING(4) LogLevel_Warning(3) // LOG_NOTICE(5) LogLevel_Info(4) // LOG_INFO(6) LogLevel_Verbose(5) // LOG_DEBUG(7) LogLevel_Debug(6) int _verb = static_cast<int>(verb); if (_verb == 1) _verb = 0; else _verb += 1; int i = sd_journal_send("MESSAGE=%s", msg, "QI_CATEGORY=%s", category, "PRIORITY=%i", _verb, "CODE_FILE=%s", file, "CODE_LINE=%i", line, "CODE_FUNC=%s", fct, NULL ); if (i == 0) return; // If it fail try to do a simpler call to journald int j = sd_journal_print(_verb, "%s; %s", category, msg); if (j == 0) return; // If it fail again print an error message std::cerr << "Can't send message to journald." << std::endl; }
static int w_sd_journal_print(struct sip_msg* msg, char* lev, char* txt) { str slev; str stxt; int ilev; if(fixup_get_svalue(msg, (gparam_t*)lev, &slev)!=0) { LM_ERR("unable to get level parameter\n"); return -1; } if(fixup_get_svalue(msg, (gparam_t*)txt, &stxt)!=0) { LM_ERR("unable to get text parameter\n"); return -1; } /* one of LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, * LOG_NOTICE, LOG_INFO, LOG_DEBUG, as defined in syslog.h, see syslog(3) */ ilev = LOG_DEBUG; if(slev.len==9 && strncasecmp(slev.s, "LOG_EMERG", slev.len)==0) { ilev = LOG_EMERG; } else if(slev.len==9 && strncasecmp(slev.s, "LOG_ALERT", slev.len)==0) { ilev = LOG_ALERT; } else if(slev.len==8 && strncasecmp(slev.s, "LOG_CRIT", slev.len)==0) { ilev = LOG_CRIT; } else if(slev.len==7 && strncasecmp(slev.s, "LOG_ERR", slev.len)==0) { ilev = LOG_ERR; } else if(slev.len==11 && strncasecmp(slev.s, "LOG_WARNING", slev.len)==0) { ilev = LOG_WARNING; } else if(slev.len==10 && strncasecmp(slev.s, "LOG_NOTICE", slev.len)==0) { ilev = LOG_NOTICE; } else if(slev.len==8 && strncasecmp(slev.s, "LOG_INFO", slev.len)==0) { ilev = LOG_INFO; } sd_journal_print(ilev, "%.*s", stxt.len, stxt.s); return 1; }
/** * main: **/ int main (int argc, char *argv[]) { PkOfflineAction action = PK_OFFLINE_ACTION_UNKNOWN; gint retval; _cleanup_error_free_ GError *error = NULL; _cleanup_main_loop_unref_ GMainLoop *loop = NULL; _cleanup_object_unref_ GFile *file = NULL; _cleanup_object_unref_ PkProgressBar *progressbar = NULL; _cleanup_object_unref_ PkResults *results = NULL; _cleanup_object_unref_ PkTask *task = NULL; _cleanup_strv_free_ gchar **package_ids = NULL; #if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 35) g_type_init (); #endif /* ensure root user */ if (getuid () != 0 || geteuid () != 0) { retval = EXIT_FAILURE; g_print ("This program can only be used using root\n"); sd_journal_print (LOG_WARNING, "not called with the root user"); goto out; } /* get the action, and then delete the file */ action = pk_offline_update_get_action (); g_unlink (PK_OFFLINE_ACTION_FILENAME); /* always do this first to avoid a loop if this tool segfaults */ g_unlink (PK_OFFLINE_TRIGGER_FILENAME); /* do stuff on ctrl-c */ g_unix_signal_add_full (G_PRIORITY_DEFAULT, SIGINT, pk_offline_update_sigint_cb, NULL, NULL); /* get the list of packages to update */ package_ids = pk_offline_get_prepared_ids (&error); if (package_ids == NULL) { retval = EXIT_FAILURE; sd_journal_print (LOG_WARNING, "failed to read %s: %s", PK_OFFLINE_PREPARED_FILENAME, error->message); goto out; } /* use a progress bar when the user presses <esc> in plymouth */ progressbar = pk_progress_bar_new (); pk_progress_bar_set_size (progressbar, 25); pk_progress_bar_set_padding (progressbar, 30); /* just update the system */ task = pk_task_new (); pk_client_set_interactive (PK_CLIENT (task), FALSE); pk_offline_update_set_plymouth_mode ("updates"); /* TRANSLATORS: we've started doing offline updates */ pk_offline_update_set_plymouth_msg (_("Installing updates, this could take a while...")); pk_offline_update_write_dummy_results (package_ids); results = pk_client_update_packages (PK_CLIENT (task), 0, package_ids, NULL, /* GCancellable */ pk_offline_update_progress_cb, progressbar, /* user_data */ &error); if (results == NULL) { retval = EXIT_FAILURE; pk_offline_update_write_error (error); sd_journal_print (LOG_WARNING, "failed to update system: %s", error->message); goto out; } pk_progress_bar_end (progressbar); pk_offline_update_write_results (results); /* delete prepared-update file if it's not already been done by the * pk-plugin-systemd-update daemon plugin */ if (!pk_offline_auth_invalidate (&error)) { retval = EXIT_FAILURE; sd_journal_print (LOG_WARNING, "failed to delete %s: %s", PK_OFFLINE_PREPARED_FILENAME, error->message); goto out; } retval = EXIT_SUCCESS; out: /* if we failed, we pause to show any error on the screen */ if (retval != EXIT_SUCCESS) { loop = g_main_loop_new (NULL, FALSE); g_timeout_add_seconds (10, pk_offline_update_loop_quit_cb, loop); g_main_loop_run (loop); } /* we have to manually either restart or shutdown */ if (action == PK_OFFLINE_ACTION_REBOOT) pk_offline_update_reboot (); else if (action == PK_OFFLINE_ACTION_POWER_OFF) pk_offline_update_power_off (); return retval; }
/** * pk_offline_update_sigint_cb: **/ static gboolean pk_offline_update_sigint_cb (gpointer user_data) { sd_journal_print (LOG_WARNING, "Handling SIGINT"); return FALSE; }
/* wrapper for inet_pton function */ void Inet_pton (int family, const char *strptr, void *addrptr) { int n = inet_pton(family, strptr, addrptr); if (n <= 0) sd_journal_print (LOG_ERR, "inet_pton returned negative value."); }
int /* O - Exit status */ main(int argc, /* I - Number of command-line args */ char *argv[]) /* I - Command-line arguments */ { int i; /* Looping var */ char *opt; /* Option character */ int close_all = 1, /* Close all file descriptors? */ disconnect = 1, /* Disconnect from controlling terminal? */ fg = 0, /* Run in foreground? */ run_as_child = 0, /* Running as child process? */ print_profile = 0; /* Print the sandbox profile to stdout? */ int fds; /* Number of ready descriptors */ cupsd_client_t *con; /* Current client */ cupsd_job_t *job; /* Current job */ cupsd_listener_t *lis; /* Current listener */ time_t current_time, /* Current time */ activity, /* Client activity timer */ senddoc_time, /* Send-Document time */ expire_time, /* Subscription expire time */ report_time, /* Malloc/client/job report time */ event_time; /* Last event notification time */ long timeout; /* Timeout for cupsdDoSelect() */ struct rlimit limit; /* Runtime limit */ #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET) struct sigaction action; /* Actions for POSIX signals */ #endif /* HAVE_SIGACTION && !HAVE_SIGSET */ #ifdef __APPLE__ int use_sysman = 1; /* Use system management functions? */ #else time_t netif_time = 0; /* Time since last network update */ #endif /* __APPLE__ */ #if defined(HAVE_ONDEMAND) int service_idle_exit; /* Idle exit on select timeout? */ #endif /* HAVE_ONDEMAND */ #ifdef HAVE_GETEUID /* * Check for setuid invocation, which we do not support! */ if (getuid() != geteuid()) { fputs("cupsd: Cannot run as a setuid program.\n", stderr); return (1); } #endif /* HAVE_GETEUID */ /* * Check for command-line arguments... */ fg = 0; #ifdef HAVE_LAUNCHD if (getenv("CUPSD_LAUNCHD")) { OnDemand = 1; fg = 1; close_all = 0; disconnect = 0; } #endif /* HAVE_LAUNCHD */ for (i = 1; i < argc; i ++) if (argv[i][0] == '-') for (opt = argv[i] + 1; *opt != '\0'; opt ++) switch (*opt) { case 'C' : /* Run as child with config file */ run_as_child = 1; fg = 1; close_all = 0; case 'c' : /* Configuration file */ i ++; if (i >= argc) { _cupsLangPuts(stderr, _("cupsd: Expected config filename " "after \"-c\" option.")); usage(1); } if (argv[i][0] == '/') { /* * Absolute directory... */ cupsdSetString(&ConfigurationFile, argv[i]); } else { /* * Relative directory... */ char *current; /* Current directory */ /* * Allocate a buffer for the current working directory to * reduce run-time stack usage; this approximates the * behavior of some implementations of getcwd() when they * are passed a NULL pointer. */ if ((current = malloc(1024)) == NULL) { _cupsLangPuts(stderr, _("cupsd: Unable to get current directory.")); return (1); } if (!getcwd(current, 1024)) { _cupsLangPuts(stderr, _("cupsd: Unable to get current directory.")); free(current); return (1); } cupsdSetStringf(&ConfigurationFile, "%s/%s", current, argv[i]); free(current); } break; case 'f' : /* Run in foreground... */ fg = 1; disconnect = 0; close_all = 0; break; case 'F' : /* Run in foreground, but disconnect from terminal... */ fg = 1; close_all = 0; break; case 'h' : /* Show usage/help */ usage(0); break; case 'l' : /* Started by launchd/systemd/upstart... */ #if defined(HAVE_ONDEMAND) OnDemand = 1; fg = 1; close_all = 0; disconnect = 0; #else _cupsLangPuts(stderr, _("cupsd: On-demand support not compiled " "in, running in normal mode.")); fg = 0; disconnect = 1; close_all = 1; #endif /* HAVE_ONDEMAND */ break; case 'p' : /* Stop immediately for profiling */ fputs("cupsd: -p (startup profiling) is for internal testing " "use only!\n", stderr); stop_scheduler = 1; fg = 1; disconnect = 0; close_all = 0; break; case 'P' : /* Disable security profiles */ fputs("cupsd: -P (disable sandboxing) is for internal testing use only.\n", stderr); UseSandboxing = 0; break; case 's' : /* Set cups-files.conf location */ i ++; if (i >= argc) { _cupsLangPuts(stderr, _("cupsd: Expected cups-files.conf " "filename after \"-s\" option.")); usage(1); } if (argv[i][0] != '/') { /* * Relative filename not allowed... */ _cupsLangPuts(stderr, _("cupsd: Relative cups-files.conf " "filename not allowed.")); usage(1); } cupsdSetString(&CupsFilesFile, argv[i]); break; #ifdef __APPLE__ case 'S' : /* Disable system management functions */ fputs("cupsd: -S (disable system management) for internal " "testing use only!\n", stderr); use_sysman = 0; break; #endif /* __APPLE__ */ case 't' : /* Test the cupsd.conf file... */ TestConfigFile = 1; fg = 1; disconnect = 0; close_all = 0; break; case 'T' : /* Print security profile */ print_profile = 1; fg = 1; disconnect = 0; close_all = 0; break; default : /* Unknown option */ _cupsLangPrintf(stderr, _("cupsd: Unknown option \"%c\" - " "aborting."), *opt); usage(1); break; } else { _cupsLangPrintf(stderr, _("cupsd: Unknown argument \"%s\" - aborting."), argv[i]); usage(1); } if (!ConfigurationFile) cupsdSetString(&ConfigurationFile, CUPS_SERVERROOT "/cupsd.conf"); if (!CupsFilesFile) { char *filename, /* Copy of cupsd.conf filename */ *slash; /* Final slash in cupsd.conf filename */ size_t len; /* Size of buffer */ len = strlen(ConfigurationFile) + 15; if ((filename = malloc(len)) == NULL) { _cupsLangPrintf(stderr, _("cupsd: Unable to get path to " "cups-files.conf file.")); return (1); } strlcpy(filename, ConfigurationFile, len); if ((slash = strrchr(filename, '/')) == NULL) { _cupsLangPrintf(stderr, _("cupsd: Unable to get path to " "cups-files.conf file.")); return (1); } strlcpy(slash, "/cups-files.conf", len - (size_t)(slash - filename)); cupsdSetString(&CupsFilesFile, filename); free(filename); } if (disconnect) { /* * Make sure we aren't tying up any filesystems... */ chdir("/"); /* * Disconnect from the controlling terminal... */ setsid(); } if (close_all) { /* * Close all open files... */ getrlimit(RLIMIT_NOFILE, &limit); for (i = 0; i < (int)limit.rlim_cur && i < 1024; i ++) close(i); /* * Redirect stdin/out/err to /dev/null... */ if ((i = open("/dev/null", O_RDONLY)) != 0) { dup2(i, 0); close(i); } if ((i = open("/dev/null", O_WRONLY)) != 1) { dup2(i, 1); close(i); } if ((i = open("/dev/null", O_WRONLY)) != 2) { dup2(i, 2); close(i); } } else LogStderr = cupsFileStderr(); /* * Run in the background as needed... */ if (!fg) { /* * Setup signal handlers for the parent... */ #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */ sigset(SIGUSR1, parent_handler); sigset(SIGCHLD, parent_handler); sigset(SIGHUP, SIG_IGN); #elif defined(HAVE_SIGACTION) memset(&action, 0, sizeof(action)); sigemptyset(&action.sa_mask); sigaddset(&action.sa_mask, SIGUSR1); action.sa_handler = parent_handler; sigaction(SIGUSR1, &action, NULL); sigaction(SIGCHLD, &action, NULL); sigemptyset(&action.sa_mask); action.sa_handler = SIG_IGN; sigaction(SIGHUP, &action, NULL); #else signal(SIGUSR1, parent_handler); signal(SIGCLD, parent_handler); signal(SIGHUP, SIG_IGN); #endif /* HAVE_SIGSET */ if (fork() > 0) { /* * OK, wait for the child to startup and send us SIGUSR1 or to crash * and the OS send us SIGCHLD... We also need to ignore SIGHUP which * might be sent by the init script to restart the scheduler... */ for (; parent_signal == 0;) sleep(1); if (parent_signal == SIGUSR1) return (0); if (wait(&i) < 0) { perror("cupsd"); return (1); } else if (WIFEXITED(i)) { fprintf(stderr, "cupsd: Child exited with status %d\n", WEXITSTATUS(i)); return (2); } else { fprintf(stderr, "cupsd: Child exited on signal %d\n", WTERMSIG(i)); return (3); } } #if defined(__OpenBSD__) && OpenBSD < 201211 /* * Call _thread_sys_closefrom() so the child process doesn't reset the * parent's file descriptors to be blocking. This is a workaround for a * limitation of userland libpthread on older versions of OpenBSD. */ _thread_sys_closefrom(0); #endif /* __OpenBSD__ && OpenBSD < 201211 */ /* * Since many system libraries create fork-unsafe data on execution of a * program, we need to re-execute the background cupsd with the "-C" and "-s" * options to avoid problems. Unfortunately, we also have to assume that * argv[0] contains the name of the cupsd executable - there is no portable * way to get the real pathname... */ execlp(argv[0], argv[0], "-C", ConfigurationFile, "-s", CupsFilesFile, (char *)0); exit(errno); } /* * Set the timezone info... */ tzset(); #ifdef LC_TIME setlocale(LC_TIME, ""); #endif /* LC_TIME */ #ifdef HAVE_DBUS_THREADS_INIT /* * Enable threading support for D-BUS... */ dbus_threads_init_default(); #endif /* HAVE_DBUS_THREADS_INIT */ /* * Set the maximum number of files... */ getrlimit(RLIMIT_NOFILE, &limit); #if !defined(HAVE_POLL) && !defined(HAVE_EPOLL) && !defined(HAVE_KQUEUE) if (limit.rlim_max > FD_SETSIZE) MaxFDs = FD_SETSIZE; else #endif /* !HAVE_POLL && !HAVE_EPOLL && !HAVE_KQUEUE */ #ifdef RLIM_INFINITY if (limit.rlim_max == RLIM_INFINITY) MaxFDs = 16384; else #endif /* RLIM_INFINITY */ MaxFDs = limit.rlim_max; limit.rlim_cur = (rlim_t)MaxFDs; setrlimit(RLIMIT_NOFILE, &limit); cupsdStartSelect(); /* * Read configuration... */ if (!cupsdReadConfiguration()) return (1); else if (TestConfigFile) { printf("\"%s\" is OK.\n", CupsFilesFile); printf("\"%s\" is OK.\n", ConfigurationFile); return (0); } else if (print_profile) { cups_file_t *fp; /* File pointer */ const char *profile = cupsdCreateProfile(42, 0); /* Profile */ char line[1024]; /* Line from file */ if ((fp = cupsFileOpen(profile, "r")) == NULL) { printf("Unable to open profile file \"%s\": %s\n", profile ? profile : "(null)", strerror(errno)); return (1); } while (cupsFileGets(fp, line, sizeof(line))) puts(line); cupsFileClose(fp); return (0); } /* * Clean out old temp files and printer cache data. */ if (!strncmp(TempDir, RequestRoot, strlen(RequestRoot))) cupsdCleanFiles(TempDir, NULL); cupsdCleanFiles(CacheDir, "*.ipp"); #if defined(HAVE_ONDEMAND) if (OnDemand) { /* * If we were started on demand by launchd or systemd get the listen sockets * file descriptors... */ service_checkin(); service_checkout(); } #endif /* HAVE_ONDEMAND */ /* * Startup the server... */ httpInitialize(); cupsdStartServer(); /* * Catch hangup and child signals and ignore broken pipes... */ #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */ sigset(SIGCHLD, sigchld_handler); sigset(SIGHUP, sighup_handler); sigset(SIGPIPE, SIG_IGN); sigset(SIGTERM, sigterm_handler); #elif defined(HAVE_SIGACTION) memset(&action, 0, sizeof(action)); sigemptyset(&action.sa_mask); sigaddset(&action.sa_mask, SIGTERM); sigaddset(&action.sa_mask, SIGCHLD); action.sa_handler = sigchld_handler; sigaction(SIGCHLD, &action, NULL); sigemptyset(&action.sa_mask); sigaddset(&action.sa_mask, SIGHUP); action.sa_handler = sighup_handler; sigaction(SIGHUP, &action, NULL); sigemptyset(&action.sa_mask); action.sa_handler = SIG_IGN; sigaction(SIGPIPE, &action, NULL); sigemptyset(&action.sa_mask); sigaddset(&action.sa_mask, SIGTERM); sigaddset(&action.sa_mask, SIGCHLD); action.sa_handler = sigterm_handler; sigaction(SIGTERM, &action, NULL); #else signal(SIGCLD, sigchld_handler); /* No, SIGCLD isn't a typo... */ signal(SIGHUP, sighup_handler); signal(SIGPIPE, SIG_IGN); signal(SIGTERM, sigterm_handler); #endif /* HAVE_SIGSET */ /* * Initialize authentication certificates... */ cupsdInitCerts(); /* * If we are running in the background, signal the parent process that * we are up and running... */ if (!fg || run_as_child) { /* * Send a signal to the parent process, but only if the parent is * not PID 1 (init). This avoids accidentally shutting down the * system on OpenBSD if you CTRL-C the server before it is up... */ i = getppid(); /* Save parent PID to avoid race condition */ if (i != 1) kill(i, SIGUSR1); } #ifdef __APPLE__ /* * Start power management framework... */ if (use_sysman) cupsdStartSystemMonitor(); #endif /* __APPLE__ */ /* * Send server-started event... */ #if defined(HAVE_ONDEMAND) if (OnDemand) cupsdAddEvent(CUPSD_EVENT_SERVER_STARTED, NULL, NULL, "Scheduler started on demand."); else #endif /* HAVE_ONDEMAND */ if (fg) cupsdAddEvent(CUPSD_EVENT_SERVER_STARTED, NULL, NULL, "Scheduler started in foreground."); else cupsdAddEvent(CUPSD_EVENT_SERVER_STARTED, NULL, NULL, "Scheduler started in background."); /* * Start any pending print jobs... */ cupsdCheckJobs(); /* * Loop forever... */ current_time = time(NULL); event_time = current_time; expire_time = current_time; fds = 1; report_time = 0; senddoc_time = current_time; while (!stop_scheduler) { /* * Check if there are dead children to handle... */ if (dead_children) process_children(); /* * Check if we need to load the server configuration file... */ if (NeedReload) { /* * Close any idle clients... */ if (cupsArrayCount(Clients) > 0) { for (con = (cupsd_client_t *)cupsArrayFirst(Clients); con; con = (cupsd_client_t *)cupsArrayNext(Clients)) if (httpGetState(con->http) == HTTP_WAITING) cupsdCloseClient(con); else con->http->keep_alive = HTTP_KEEPALIVE_OFF; cupsdPauseListening(); } /* * Restart if all clients are closed and all jobs finished, or * if the reload timeout has elapsed... */ if ((cupsArrayCount(Clients) == 0 && (cupsArrayCount(PrintingJobs) == 0 || NeedReload != RELOAD_ALL)) || (time(NULL) - ReloadTime) >= ReloadTimeout) { /* * Shutdown the server... */ #ifdef HAVE_ONDEMAND if (OnDemand) break; #endif /* HAVE_ONDEMAND */ DoingShutdown = 1; cupsdStopServer(); /* * Read configuration... */ if (!cupsdReadConfiguration()) { #ifdef HAVE_SYSTEMD_SD_JOURNAL_H sd_journal_print(LOG_ERR, "Unable to read configuration file \"%s\" - exiting.", ConfigurationFile); #else syslog(LOG_LPR, "Unable to read configuration file \'%s\' - exiting.", ConfigurationFile); #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */ break; } /* * Startup the server... */ DoingShutdown = 0; cupsdStartServer(); /* * Send a server-restarted event... */ cupsdAddEvent(CUPSD_EVENT_SERVER_RESTARTED, NULL, NULL, "Scheduler restarted."); } } /* * Check for available input or ready output. If cupsdDoSelect() * returns 0 or -1, something bad happened and we should exit * immediately. * * Note that we at least have one listening socket open at all * times. */ if ((timeout = select_timeout(fds)) > 1 && LastEvent) timeout = 1; #ifdef HAVE_ONDEMAND /* * If no other work is scheduled and we're being controlled by * launchd then timeout after 'LaunchdTimeout' seconds of * inactivity... */ if (timeout == 86400 && OnDemand && IdleExitTimeout && !cupsArrayCount(ActiveJobs) && # ifdef HAVE_SYSTEMD !WebInterface && # endif /* HAVE_SYSTEMD */ (!Browsing || !BrowseLocalProtocols || !cupsArrayCount(Printers))) { timeout = IdleExitTimeout; service_idle_exit = 1; } else service_idle_exit = 0; #endif /* HAVE_ONDEMAND */ if ((fds = cupsdDoSelect(timeout)) < 0) { /* * Got an error from select! */ #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) cupsd_printer_t *p; /* Current printer */ #endif /* HAVE_DNSSD || HAVE_AVAHI */ if (errno == EINTR) /* Just interrupted by a signal */ continue; /* * Log all sorts of debug info to help track down the problem. */ cupsdLogMessage(CUPSD_LOG_EMERG, "cupsdDoSelect() failed - %s!", strerror(errno)); for (i = 0, con = (cupsd_client_t *)cupsArrayFirst(Clients); con; i ++, con = (cupsd_client_t *)cupsArrayNext(Clients)) cupsdLogMessage(CUPSD_LOG_EMERG, "Clients[%d] = %d, file = %d, state = %d", i, con->number, con->file, httpGetState(con->http)); for (i = 0, lis = (cupsd_listener_t *)cupsArrayFirst(Listeners); lis; i ++, lis = (cupsd_listener_t *)cupsArrayNext(Listeners)) cupsdLogMessage(CUPSD_LOG_EMERG, "Listeners[%d] = %d", i, lis->fd); cupsdLogMessage(CUPSD_LOG_EMERG, "CGIPipes[0] = %d", CGIPipes[0]); #ifdef __APPLE__ cupsdLogMessage(CUPSD_LOG_EMERG, "SysEventPipes[0] = %d", SysEventPipes[0]); #endif /* __APPLE__ */ for (job = (cupsd_job_t *)cupsArrayFirst(ActiveJobs); job; job = (cupsd_job_t *)cupsArrayNext(ActiveJobs)) cupsdLogMessage(CUPSD_LOG_EMERG, "Jobs[%d] = %d < [%d %d] > [%d %d]", job->id, job->status_buffer ? job->status_buffer->fd : -1, job->print_pipes[0], job->print_pipes[1], job->back_pipes[0], job->back_pipes[1]); #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI) for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); p; p = (cupsd_printer_t *)cupsArrayNext(Printers)) cupsdLogMessage(CUPSD_LOG_EMERG, "printer[%s] reg_name=\"%s\"", p->name, p->reg_name ? p->reg_name : "(null)"); #endif /* HAVE_DNSSD || HAVE_AVAHI */ break; } current_time = time(NULL); /* * Write dirty config/state files... */ if (DirtyCleanTime && current_time >= DirtyCleanTime) cupsdCleanDirty(); #ifdef __APPLE__ /* * If we are going to sleep and still have pending jobs, stop them after * a period of time... */ if (SleepJobs > 0 && current_time >= SleepJobs && cupsArrayCount(PrintingJobs) > 0) { SleepJobs = 0; cupsdStopAllJobs(CUPSD_JOB_DEFAULT, 5); } #endif /* __APPLE__ */ #ifndef __APPLE__ /* * Update the network interfaces once a minute... */ if ((current_time - netif_time) >= 60) { netif_time = current_time; NetIFUpdate = 1; } #endif /* !__APPLE__ */ #ifdef HAVE_ONDEMAND /* * If no other work was scheduled and we're being controlled by launchd, * systemd, or upstart then timeout after 'LaunchdTimeout' seconds of * inactivity... */ if (!fds && service_idle_exit) { cupsdLogMessage(CUPSD_LOG_INFO, "Printer sharing is off and there are no jobs pending, " "will restart on demand."); stop_scheduler = 1; break; } #endif /* HAVE_ONDEMAND */ /* * Resume listening for new connections as needed... */ if (ListeningPaused && ListeningPaused <= current_time && cupsArrayCount(Clients) < MaxClients) cupsdResumeListening(); /* * Expire subscriptions and unload completed jobs as needed... */ if (current_time > expire_time) { if (cupsArrayCount(Subscriptions) > 0) cupsdExpireSubscriptions(NULL, NULL); cupsdUnloadCompletedJobs(); expire_time = current_time; } #ifndef HAVE_AUTHORIZATION_H /* * Update the root certificate once every 5 minutes if we have client * connections... */ if ((current_time - RootCertTime) >= RootCertDuration && RootCertDuration && !RunUser && cupsArrayCount(Clients)) { /* * Update the root certificate... */ cupsdDeleteCert(0); cupsdAddCert(0, "root", cupsdDefaultAuthType()); } #endif /* !HAVE_AUTHORIZATION_H */ /* * Check for new data on the client sockets... */ for (con = (cupsd_client_t *)cupsArrayFirst(Clients); con; con = (cupsd_client_t *)cupsArrayNext(Clients)) { /* * Process pending data in the input buffer... */ if (httpGetReady(con->http)) { cupsdReadClient(con); continue; } /* * Check the activity and close old clients... */ activity = current_time - Timeout; if (httpGetActivity(con->http) < activity && !con->pipe_pid) { cupsdLogMessage(CUPSD_LOG_DEBUG, "Closing client %d after %d seconds of inactivity.", con->number, Timeout); cupsdCloseClient(con); continue; } } /* * Update any pending multi-file documents... */ if ((current_time - senddoc_time) >= 10) { cupsdCheckJobs(); senddoc_time = current_time; } /* * Clean job history... */ if (JobHistoryUpdate && current_time >= JobHistoryUpdate) cupsdCleanJobs(); /* * Log statistics at most once a minute when in debug mode... */ if ((current_time - report_time) >= 60 && LogLevel >= CUPSD_LOG_DEBUG) { size_t string_count, /* String count */ alloc_bytes, /* Allocated string bytes */ total_bytes; /* Total string bytes */ #ifdef HAVE_MALLINFO struct mallinfo mem; /* Malloc information */ mem = mallinfo(); cupsdLogMessage(CUPSD_LOG_DEBUG, "Report: malloc-arena=%lu", mem.arena); cupsdLogMessage(CUPSD_LOG_DEBUG, "Report: malloc-used=%lu", mem.usmblks + mem.uordblks); cupsdLogMessage(CUPSD_LOG_DEBUG, "Report: malloc-free=%lu", mem.fsmblks + mem.fordblks); #endif /* HAVE_MALLINFO */ cupsdLogMessage(CUPSD_LOG_DEBUG, "Report: clients=%d", cupsArrayCount(Clients)); cupsdLogMessage(CUPSD_LOG_DEBUG, "Report: jobs=%d", cupsArrayCount(Jobs)); cupsdLogMessage(CUPSD_LOG_DEBUG, "Report: jobs-active=%d", cupsArrayCount(ActiveJobs)); cupsdLogMessage(CUPSD_LOG_DEBUG, "Report: printers=%d", cupsArrayCount(Printers)); string_count = _cupsStrStatistics(&alloc_bytes, &total_bytes); cupsdLogMessage(CUPSD_LOG_DEBUG, "Report: stringpool-string-count=" CUPS_LLFMT, CUPS_LLCAST string_count); cupsdLogMessage(CUPSD_LOG_DEBUG, "Report: stringpool-alloc-bytes=" CUPS_LLFMT, CUPS_LLCAST alloc_bytes); cupsdLogMessage(CUPSD_LOG_DEBUG, "Report: stringpool-total-bytes=" CUPS_LLFMT, CUPS_LLCAST total_bytes); report_time = current_time; } /* * Handle OS-specific event notification for any events that have * accumulated. Don't send these more than once a second... */ if (LastEvent && (current_time - event_time) >= 1) { #ifdef HAVE_NOTIFY_POST if (LastEvent & (CUPSD_EVENT_PRINTER_ADDED | CUPSD_EVENT_PRINTER_DELETED | CUPSD_EVENT_PRINTER_MODIFIED)) { cupsdLogMessage(CUPSD_LOG_DEBUG2, "notify_post(\"com.apple.printerListChange\")"); notify_post("com.apple.printerListChange"); } if (LastEvent & CUPSD_EVENT_PRINTER_STATE_CHANGED) { cupsdLogMessage(CUPSD_LOG_DEBUG2, "notify_post(\"com.apple.printerHistoryChange\")"); notify_post("com.apple.printerHistoryChange"); } if (LastEvent & (CUPSD_EVENT_JOB_STATE_CHANGED | CUPSD_EVENT_JOB_CONFIG_CHANGED | CUPSD_EVENT_JOB_PROGRESS)) { cupsdLogMessage(CUPSD_LOG_DEBUG2, "notify_post(\"com.apple.jobChange\")"); notify_post("com.apple.jobChange"); } #endif /* HAVE_NOTIFY_POST */ /* * Reset the accumulated events... */ LastEvent = CUPSD_EVENT_NONE; event_time = current_time; } } /* * Log a message based on what happened... */ if (stop_scheduler) { cupsdLogMessage(CUPSD_LOG_INFO, "Scheduler shutting down normally."); cupsdAddEvent(CUPSD_EVENT_SERVER_STOPPED, NULL, NULL, "Scheduler shutting down normally."); } else { cupsdLogMessage(CUPSD_LOG_ERROR, "Scheduler shutting down due to program error."); cupsdAddEvent(CUPSD_EVENT_SERVER_STOPPED, NULL, NULL, "Scheduler shutting down due to program error."); } /* * Close all network clients... */ DoingShutdown = 1; cupsdStopServer(); #ifdef HAVE_ONDEMAND /* * Update the keep-alive file as needed... */ if (OnDemand) service_checkout(); #endif /* HAVE_ONDEMAND */ /* * Stop all jobs... */ cupsdFreeAllJobs(); #ifdef __APPLE__ /* * Stop monitoring system event monitoring... */ if (use_sysman) cupsdStopSystemMonitor(); #endif /* __APPLE__ */ cupsdStopSelect(); return (!stop_scheduler); }
/** * pk_offline_update_progress_cb: **/ static void pk_offline_update_progress_cb (PkProgress *progress, PkProgressType type, gpointer user_data) { PkInfoEnum info; PkProgressBar *progressbar = PK_PROGRESS_BAR (user_data); PkStatusEnum status; gint percentage; _cleanup_free_ gchar *msg = NULL; _cleanup_object_unref_ PkPackage *pkg = NULL; switch (type) { case PK_PROGRESS_TYPE_ROLE: sd_journal_print (LOG_INFO, "assigned role"); pk_progress_bar_start (progressbar, "Updating system"); break; case PK_PROGRESS_TYPE_PACKAGE: g_object_get (progress, "package", &pkg, NULL); info = pk_package_get_info (pkg); if (info == PK_INFO_ENUM_UPDATING) { msg = g_strdup_printf ("Updating %s", pk_package_get_name (pkg)); pk_progress_bar_start (progressbar, msg); } else if (info == PK_INFO_ENUM_INSTALLING) { msg = g_strdup_printf ("Installing %s", pk_package_get_name (pkg)); pk_progress_bar_start (progressbar, msg); } else if (info == PK_INFO_ENUM_REMOVING) { msg = g_strdup_printf ("Removing %s", pk_package_get_name (pkg)); pk_progress_bar_start (progressbar, msg); } sd_journal_print (LOG_INFO, "package %s\t%s-%s.%s (%s)", pk_info_enum_to_string (info), pk_package_get_name (pkg), pk_package_get_version (pkg), pk_package_get_arch (pkg), pk_package_get_data (pkg)); break; case PK_PROGRESS_TYPE_PERCENTAGE: g_object_get (progress, "percentage", &percentage, NULL); if (percentage < 0) return; sd_journal_print (LOG_INFO, "percentage %i%%", percentage); /* TRANSLATORS: this is the message we send plymouth to * advise of the new percentage completion */ msg = g_strdup_printf ("%s - %i%%", _("Installing Updates"), percentage); if (percentage > 10) pk_offline_update_set_plymouth_msg (msg); /* print on terminal */ pk_progress_bar_set_percentage (progressbar, percentage); /* update plymouth */ pk_offline_update_set_plymouth_percentage (percentage); break; case PK_PROGRESS_TYPE_STATUS: g_object_get (progress, "status", &status, NULL); sd_journal_print (LOG_INFO, "status %s", pk_status_enum_to_string (status)); default: break; } }
int /* O - 1 if log file open */ cupsdCheckLogFile(cups_file_t **lf, /* IO - Log file */ const char *logname) /* I - Log filename */ { char backname[1024], /* Backup log filename */ filename[1024], /* Formatted log filename */ *ptr; /* Pointer into filename */ const char *logptr; /* Pointer into log filename */ /* * See if we have a log file to check... */ if (!lf || !logname || !logname[0]) return (1); /* * Handle logging to stderr... */ if (!strcmp(logname, "stderr")) { *lf = LogStderr; return (1); } /* * Format the filename as needed... */ if (!*lf || (strncmp(logname, "/dev/", 5) && cupsFileTell(*lf) > MaxLogSize && MaxLogSize > 0)) { /* * Handle format strings... */ filename[sizeof(filename) - 1] = '\0'; if (logname[0] != '/') { strlcpy(filename, ServerRoot, sizeof(filename)); strlcat(filename, "/", sizeof(filename)); } else filename[0] = '\0'; for (logptr = logname, ptr = filename + strlen(filename); *logptr && ptr < (filename + sizeof(filename) - 1); logptr ++) if (*logptr == '%') { /* * Format spec... */ logptr ++; if (*logptr == 's') { /* * Insert the server name... */ strlcpy(ptr, ServerName, sizeof(filename) - (size_t)(ptr - filename)); ptr += strlen(ptr); } else { /* * Otherwise just insert the character... */ *ptr++ = *logptr; } } else *ptr++ = *logptr; *ptr = '\0'; } /* * See if the log file is open... */ if (!*lf) { /* * Nope, open the log file... */ if ((*lf = cupsFileOpen(filename, "a")) == NULL) { /* * If the file is in CUPS_LOGDIR then try to create a missing directory... */ if (!strncmp(filename, CUPS_LOGDIR, strlen(CUPS_LOGDIR))) { /* * Try updating the permissions of the containing log directory, using * the log file permissions as a basis... */ mode_t log_dir_perm = (mode_t)(0300 | LogFilePerm); /* LogFilePerm + owner write/search */ if (log_dir_perm & 0040) log_dir_perm |= 0010; /* Add group search */ if (log_dir_perm & 0004) log_dir_perm |= 0001; /* Add other search */ cupsdCheckPermissions(CUPS_LOGDIR, NULL, log_dir_perm, RunUser, Group, 1, -1); *lf = cupsFileOpen(filename, "a"); } if (*lf == NULL) { #ifdef HAVE_SYSTEMD_SD_JOURNAL_H sd_journal_print(LOG_ERR, "Unable to open log file \"%s\" - %s", filename, strerror(errno)); #else syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename, strerror(errno)); #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */ if (FatalErrors & CUPSD_FATAL_LOG) cupsdEndProcess(getpid(), 0); return (0); } } if (strncmp(filename, "/dev/", 5)) { /* * Change ownership and permissions of non-device logs... */ fchown(cupsFileNumber(*lf), RunUser, Group); fchmod(cupsFileNumber(*lf), LogFilePerm); } } /* * Do we need to rotate the log? */ if (strncmp(logname, "/dev/", 5) && cupsFileTell(*lf) > MaxLogSize && MaxLogSize > 0) { /* * Rotate log file... */ cupsFileClose(*lf); strlcpy(backname, filename, sizeof(backname)); strlcat(backname, ".O", sizeof(backname)); unlink(backname); rename(filename, backname); if ((*lf = cupsFileOpen(filename, "a")) == NULL) { #ifdef HAVE_SYSTEMD_SD_JOURNAL_H sd_journal_print(LOG_ERR, "Unable to open log file \"%s\" - %s", filename, strerror(errno)); #else syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename, strerror(errno)); #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */ if (FatalErrors & CUPSD_FATAL_LOG) cupsdEndProcess(getpid(), 0); return (0); } /* * Change ownership and permissions of non-device logs... */ fchown(cupsFileNumber(*lf), RunUser, Group); fchmod(cupsFileNumber(*lf), LogFilePerm); } return (1); }
HmiService::HmiService(DBus::Connection &connection) : DBus::ObjectAdaptor(connection, GDP_DBUS_SERVICE_PATH) { sd_journal_print(LOG_INFO, "HmiService - constructor (path= %s)\n", GDP_DBUS_SERVICE_PATH); }
int64_t HmiService::GetId() { sd_journal_print(LOG_DEBUG, "HmiService::GetId() - %d\n", getpid()); return getpid(); }