+static int job_wait(struct sd_bus *bus, struct sd_bus_message *job)
+{
+ int rc;
+ sd_bus_error err = SD_BUS_ERROR_NULL;
+ const char *jpath = NULL;
+ char *jstate;
+ struct timespec tispec;
+ const int period_ms = 10;
+ const int trial_s = 10;
+ const int trial_count = (trial_s * 1000) / period_ms;
+ const int period_ns = period_ms * 1000000;
+ int trial;
+
+ /* Get job path */
+ rc = sd_bus_message_read_basic(job, 'o', &jpath);
+ if (rc < 0)
+ return rc;
+
+ /* Wait for job to enter "running" state */
+ rc = 0;
+ for (trial = 1 ; trial <= trial_count ; trial++) {
+ jstate = NULL;
+ if(sd_bus_get_property_string(bus, sdb_destination, jpath, sdbi_job, sdbj_state, &err, &jstate) >= 0) {
+ if(jstate && strcmp(jstate, sds_job_state_names[SysD_Job_State_Running]) == 0) {
+ free(jstate);
+ break;
+ } else {
+ tispec.tv_sec = 0;
+ tispec.tv_nsec = period_ns;
+ nanosleep(&tispec, NULL);
+ }
+ free(jstate);
+ }
+ }
+ if(trial > trial_count)
+ rc = -1;
+
+ return rc;
+}
+