static int on_runlevel(Context *c) { int r = 0, q, previous, runlevel; assert(c); /* We finished changing runlevel, so let's write the * utmp record and send the audit msg */ /* First, get last runlevel */ if ((q = utmp_get_runlevel(&previous, NULL)) < 0) { if (q != -ESRCH && q != -ENOENT) { log_error("Failed to get current runlevel: %s", strerror(-q)); return q; } /* Hmm, we didn't find any runlevel, that means we * have been rebooted */ r = on_reboot(c); previous = 0; } /* Secondly, get new runlevel */ if ((runlevel = get_current_runlevel(c)) < 0) return runlevel; if (previous == runlevel) return 0; #ifdef HAVE_AUDIT if (c->audit_fd >= 0) { char *s = NULL; if (asprintf(&s, "old-level=%c new-level=%c", previous > 0 ? previous : 'N', runlevel > 0 ? runlevel : 'N') < 0) return -ENOMEM; if (audit_log_user_message(c->audit_fd, AUDIT_SYSTEM_RUNLEVEL, s, NULL, NULL, NULL, 1) < 0) { log_error("Failed to send audit message: %m"); r = -errno; } free(s); } #endif if ((q = utmp_put_runlevel(0, runlevel, previous)) < 0) { log_error("Failed to write utmp record: %s", strerror(-q)); r = q; } return r; }
void TicTacToe::work() { if (objectName().isEmpty()) setObjectName(QString::fromUtf8("MagnificientNothing")); int total = SIZE * SIZE; resize(SIZE * 52 + 2, SIZE * 52 + 2); typer = true; gridWidget = new QWidget(this); gridWidget->setGeometry(QRect(0, 0, SIZE * 52 + 2, SIZE * 52 + 2)); gridLayout = new QGridLayout(gridWidget); gridLayout->setSpacing(2); gridLayout->setContentsMargins(0,0,0,0); gridLayout->setObjectName(QString::fromUtf8("gridLayout")); for (int i = 0; i < total; i++) { control[i] = 0; pushButton[i] = new QPushButton(gridWidget); pushButton[i]->setObjectName(QString("%1").arg(i)); pushButton[i]->setIcon(Cheng); pushButton[i]->setIconSize(icon_s); connect(pushButton[i], SIGNAL(clicked()), &mapper, SLOT(map())); connect(this, SIGNAL(check()), this, SLOT(on_check)); mapper.setMapping(pushButton[i], i); gridLayout->addWidget(pushButton[i], i / SIZE, i % SIZE, 1, 1); } connect(&mapper, SIGNAL(mapped(int)), this, SLOT(procede(int))); connect(this, SIGNAL(check()), this, SLOT(on_check())); connect(this, SIGNAL(win(int)), this, SLOT(on_win(int))); connect(this, SIGNAL(reboot()), this, SLOT(on_reboot())); setWindowTitle(QApplication::translate("MagnificientNothing", "MMortaaaaal Combaaat!!!", 0, QApplication::UnicodeUTF8)); }
int main(int argc, char *argv[]) { int r; DBusError error; Context c; dbus_error_init(&error); zero(c); #ifdef HAVE_AUDIT c.audit_fd = -1; #endif if (getppid() != 1) { log_error("This program should be invoked by init only."); return EXIT_FAILURE; } if (argc != 2) { log_error("This program requires one argument."); return EXIT_FAILURE; } log_set_target(LOG_TARGET_SYSLOG_OR_KMSG); log_parse_environment(); log_open(); #ifdef HAVE_AUDIT if ((c.audit_fd = audit_open()) < 0) log_error("Failed to connect to audit log: %m"); #endif if (bus_connect(DBUS_BUS_SYSTEM, &c.bus, NULL, &error) < 0) { log_error("Failed to get D-Bus connection: %s", bus_error_message(&error)); r = -EIO; goto finish; } log_debug("systemd-update-utmp running as pid %lu", (unsigned long) getpid()); if (streq(argv[1], "reboot")) r = on_reboot(&c); else if (streq(argv[1], "shutdown")) r = on_shutdown(&c); else if (streq(argv[1], "runlevel")) r = on_runlevel(&c); else { log_error("Unknown command %s", argv[1]); r = -EINVAL; } log_debug("systemd-update-utmp stopped as pid %lu", (unsigned long) getpid()); finish: #ifdef HAVE_AUDIT if (c.audit_fd >= 0) audit_close(c.audit_fd); #endif if (c.bus) { dbus_connection_flush(c.bus); dbus_connection_close(c.bus); dbus_connection_unref(c.bus); } dbus_error_free(&error); dbus_shutdown(); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }