Пример #1
0
static void busname_trigger_notify(Unit *u, Unit *other) {
        BusName *n = BUSNAME(u);

        assert(n);
        assert(other);

        if (!IN_SET(n->state, BUSNAME_RUNNING, BUSNAME_LISTENING))
                return;

        if (other->start_limit_hit) {
                busname_enter_dead(n, BUSNAME_FAILURE_SERVICE_START_LIMIT_HIT);
                return;
        }

        if (other->load_state != UNIT_LOADED || other->type != UNIT_SERVICE)
                return;

        if (IN_SET(SERVICE(other)->state,
                   SERVICE_DEAD, SERVICE_FAILED,
                   SERVICE_FINAL_SIGTERM, SERVICE_FINAL_SIGKILL,
                   SERVICE_AUTO_RESTART))
                busname_enter_listening(n);

        if (SERVICE(other)->state == SERVICE_RUNNING)
                busname_set_state(n, BUSNAME_RUNNING);
}
Пример #2
0
/****************************************************************************
Build the print command in the supplied buffer. This means getting the
print command for the service and inserting the printer name and the
print file name. Return NULL on error, else the passed buffer pointer.
****************************************************************************/
static char *build_print_command(int cnum, char *command, char *syscmd, char *filename1)
{
  int snum = SNUM(cnum);
  char *tstr;
  pstring filename;
  
  /* get the print command for the service. */
  tstr = command;
  if (!syscmd || !tstr) {
    DEBUG(0,("No print command for service `%s'\n", SERVICE(snum)));
    return (NULL);
  }

  /* copy the command into the buffer for extensive meddling. */
  StrnCpy(syscmd, tstr, sizeof(pstring) - 1);
  
  /* look for "%s" in the string. If there is no %s, we cannot print. */   
  if (!strstr(syscmd, "%s") && !strstr(syscmd, "%f")) {
    DEBUG(2,("WARNING! No placeholder for the filename in the print command for service %s!\n", SERVICE(snum)));
  }
  
  if (strstr(syscmd,"%s")) {
    int iOffset = PTR_DIFF(strstr(syscmd, "%s"),syscmd);
    
    /* construct the full path for the filename, shouldn't be necessary unless
       the subshell causes a "cd" to be executed.
       Only use the full path if there isn't a / preceding the %s */
    if (iOffset==0 || syscmd[iOffset-1] != '/') {
      StrnCpy(filename,Connections[cnum].connectpath,sizeof(filename)-1);
      trim_string(filename,"","/");
      pstrcat(filename,"/");
      pstrcat(filename,filename1);
    }
    else
      pstrcpy(filename,filename1);
    
    string_sub(syscmd, "%s", filename);
  }
  
  string_sub(syscmd, "%f", filename1);
  
  /* Does the service have a printername? If not, make a fake and empty    */
  /* printer name. That way a %p is treated sanely if no printer */
  /* name was specified to replace it. This eventuality is logged.         */
  tstr = PRINTERNAME(snum);
  if (tstr == NULL || tstr[0] == '\0') {
    DEBUG(3,( "No printer name - using %s.\n", SERVICE(snum)));
    tstr = SERVICE(snum);
  }
  
  string_sub(syscmd, "%p", tstr);
  
  standard_sub(cnum,syscmd);
  
  return (syscmd);
}
Пример #3
0
void Notification::init()
{
    // define all notification services here
    SERVICE(TYPE_MSGBOX, NotificationService_qt);
    SERVICE(TYPE_NOTIFYSEND, NotificationService_NotifySend);
#ifdef USE_LIBNOTIFY
    SERVICE(TYPE_LIBNOTIFY, NotificationService_libnotify);
#endif

    // default to msgbox
    m_type = TYPE_MSGBOX;
}
Пример #4
0
static void check(Manager *m, Unit *unit, int status_expected, int code_expected) {
        Service *service = NULL;
        usec_t ts;
        usec_t timeout = 2 * USEC_PER_SEC;

        assert_se(m);
        assert_se(unit);

        service = SERVICE(unit);
        printf("%s\n", unit->id);
        exec_context_dump(&service->exec_context, stdout, "\t");
        ts = now(CLOCK_MONOTONIC);
        while (service->state != SERVICE_DEAD && service->state != SERVICE_FAILED) {
                int r;
                usec_t n;

                r = sd_event_run(m->event, 100 * USEC_PER_MSEC);
                assert_se(r >= 0);

                n = now(CLOCK_MONOTONIC);
                if (ts + timeout < n) {
                        log_error("Test timeout when testing %s", unit->id);
                        exit(EXIT_FAILURE);
                }
        }
        exec_status_dump(&service->main_exec_status, stdout, "\t");
        assert_se(service->main_exec_status.status == status_expected);
        assert_se(service->main_exec_status.code == code_expected);
}
static int busname_start(Unit *u) {
        BusName *n = BUSNAME(u);

        assert(n);

        /* We cannot fulfill this request right now, try again later
         * please! */
        if (IN_SET(n->state, BUSNAME_SIGTERM, BUSNAME_SIGKILL))
                return -EAGAIN;

        /* Already on it! */
        if (n->state == BUSNAME_MAKING)
                return 0;

        if (n->activating && UNIT_ISSET(n->service)) {
                Service *service;

                service = SERVICE(UNIT_DEREF(n->service));

                if (UNIT(service)->load_state != UNIT_LOADED) {
                        log_unit_error(u->id, "Bus service %s not loaded, refusing.", UNIT(service)->id);
                        return -ENOENT;
                }
        }

        assert(IN_SET(n->state, BUSNAME_DEAD, BUSNAME_FAILED));

        n->result = BUSNAME_SUCCESS;
        busname_enter_making(n);

        return 1;
}
Пример #6
0
DBusHandlerResult bus_service_message_handler(Unit *u, DBusConnection *connection, DBusMessage *message) {
        Service *s = SERVICE(u);

        const BusBoundProperties bps[] = {
                { "org.freedesktop.systemd1.Unit",    bus_unit_properties,             u },
                { "org.freedesktop.systemd1.Service", bus_service_properties,          s },
                { "org.freedesktop.systemd1.Service", bus_exec_context_properties,     &s->exec_context },
                { "org.freedesktop.systemd1.Service", bus_kill_context_properties,     &s->kill_context },
                { "org.freedesktop.systemd1.Service", bus_exec_main_status_properties, &s->main_exec_status },
                { "org.freedesktop.systemd1.Service", bus_unit_cgroup_properties,      u },
                { NULL, }
        };

        SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "status");

        return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, bps);
}
static void busname_trigger_notify(Unit *u, Unit *other) {
        BusName *n = BUSNAME(u);
        Service *s;

        assert(n);
        assert(other);

        if (!IN_SET(n->state, BUSNAME_RUNNING, BUSNAME_LISTENING))
                return;

        if (other->load_state != UNIT_LOADED || other->type != UNIT_SERVICE)
                return;

        s = SERVICE(other);

        if (s->state == SERVICE_FAILED && s->result == SERVICE_FAILURE_START_LIMIT)
                busname_enter_dead(n, BUSNAME_FAILURE_SERVICE_FAILED_PERMANENT);
        else if (IN_SET(s->state,
                        SERVICE_DEAD, SERVICE_FAILED,
                        SERVICE_STOP, SERVICE_STOP_SIGTERM, SERVICE_STOP_SIGKILL,
                        SERVICE_STOP_POST, SERVICE_FINAL_SIGTERM, SERVICE_FINAL_SIGKILL,
                        SERVICE_AUTO_RESTART))
                busname_enter_listening(n);
}
#define SERVICE(x) UserEnums::URType( UserEnums::UR_NO_LEVEL, (UserEnums::x) )
#define LEVEL(x) UserEnums::URType( (UserEnums::x),\
                                     UserEnums::userRightService(0))

// These names are in utf-8
const UserEnumNames::name_entry_t
UserEnumNames::c_names[] =
{
   // These ones will not be displayed to the user currently.
   { LangTypes::english, LEVEL( UR_TRIAL),              "Trial"         },
   { LangTypes::english, LEVEL( UR_SILVER),             "Silver"        },
   { LangTypes::english, LEVEL( UR_GOLD),               "Gold"          },
   { LangTypes::swedish, LEVEL( UR_GOLD),               "Guld"          },
   { LangTypes::english, LEVEL( UR_DEMO),               "Demo"          },
   { LangTypes::english, SERVICE( UR_WF ),              "Wayfinder Navigator"},
   { LangTypes::english, SERVICE( UR_MYWAYFINDER),      "myWayfinder"   },
   { LangTypes::english, SERVICE( UR_MAPDL_PREGEN ),    "Map Download"  },
   { LangTypes::english, SERVICE( UR_MAPDL_CUSTOM ),    "Map Download"  },
   { LangTypes::english, SERVICE( UR_XML ),             "XML"           },
   { LangTypes::english, SERVICE( UR_TRAFFIC     ),     "Traffic info"  },
   { LangTypes::english, SERVICE( UR_SPEEDCAM    ),     "Speed cameras" },   
   { LangTypes::english, SERVICE( UR_FREE_TRAFFIC ),    "Free Traffic Info" },
   { LangTypes::swedish, SERVICE( UR_FREE_TRAFFIC ),    "Gratis trafikinfo" },

   // This poi type right is probably good to translate too. 
   { LangTypes::english, SERVICE( UR_POSITIONING ),     "Positioning"   },
   { LangTypes::english, SERVICE( UR_USE_GPS ),         "Use GPS"   },
   { LangTypes::english, SERVICE( UR_ROUTE ),           "Route"   },
   { LangTypes::english, SERVICE( UR_SEARCH ),          "SEARCH"   },
   { LangTypes::english, SERVICE( UR_POI ),             "POI"   },
Пример #9
0
int main(int argc, char *argv[]) {
        Manager *m = NULL;
        Unit *idle_ok, *idle_bad, *rr_ok, *rr_bad, *rr_sched;
        Service *ser;
        FILE *serial = NULL;
        FDSet *fdset = NULL;
        int r;

        /* prepare the test */
        assert_se(set_unit_path(TEST_DIR) >= 0);
        r = manager_new(MANAGER_USER, true, &m);
        if (IN_SET(r, -EPERM, -EACCES, -EADDRINUSE, -EHOSTDOWN, -ENOENT, -ENOEXEC)) {
                printf("Skipping test: manager_new: %s", strerror(-r));
                return EXIT_TEST_SKIP;
        }
        assert_se(r >= 0);
        assert_se(manager_startup(m, serial, fdset) >= 0);

        /* load idle ok */
        assert_se(manager_load_unit(m, "sched_idle_ok.service", NULL, NULL, &idle_ok) >= 0);
        assert_se(idle_ok->load_state == UNIT_LOADED);
        ser = SERVICE(idle_ok);
        assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER);
        assert_se(ser->exec_context.cpu_sched_priority == 0);

        /*
         * load idle bad. This should print a warning but we have no way to look at it.
         */
        assert_se(manager_load_unit(m, "sched_idle_bad.service", NULL, NULL, &idle_bad) >= 0);
        assert_se(idle_bad->load_state == UNIT_LOADED);
        ser = SERVICE(idle_ok);
        assert_se(ser->exec_context.cpu_sched_policy == SCHED_OTHER);
        assert_se(ser->exec_context.cpu_sched_priority == 0);

        /*
         * load rr ok.
         * Test that the default priority is moving from 0 to 1.
         */
        assert_se(manager_load_unit(m, "sched_rr_ok.service", NULL, NULL, &rr_ok) >= 0);
        assert_se(rr_ok->load_state == UNIT_LOADED);
        ser = SERVICE(rr_ok);
        assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
        assert_se(ser->exec_context.cpu_sched_priority == 1);

        /*
         * load rr bad.
         * Test that the value of 0 and 100 is ignored.
         */
        assert_se(manager_load_unit(m, "sched_rr_bad.service", NULL, NULL, &rr_bad) >= 0);
        assert_se(rr_bad->load_state == UNIT_LOADED);
        ser = SERVICE(rr_bad);
        assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
        assert_se(ser->exec_context.cpu_sched_priority == 1);

        /*
         * load rr change.
         * Test that anything between 1 and 99 can be set.
         */
        assert_se(manager_load_unit(m, "sched_rr_change.service", NULL, NULL, &rr_sched) >= 0);
        assert_se(rr_sched->load_state == UNIT_LOADED);
        ser = SERVICE(rr_sched);
        assert_se(ser->exec_context.cpu_sched_policy == SCHED_RR);
        assert_se(ser->exec_context.cpu_sched_priority == 99);

        manager_free(m);

        return EXIT_SUCCESS;
}