encode.c (1557B)
1 #include "service.h" 2 3 4 void service_encode(struct service* s, struct service_serial* buffer) { 5 uint64_t tai = (uint64_t) s->state_change + 4611686018427387914llu; 6 7 buffer->status_change[0] = (tai >> 56) & 0xff; 8 buffer->status_change[1] = (tai >> 48) & 0xff; 9 buffer->status_change[2] = (tai >> 40) & 0xff; 10 buffer->status_change[3] = (tai >> 32) & 0xff; 11 buffer->status_change[4] = (tai >> 24) & 0xff; 12 buffer->status_change[5] = (tai >> 16) & 0xff; 13 buffer->status_change[6] = (tai >> 8) & 0xff; 14 buffer->status_change[7] = (tai >> 0) & 0xff; 15 16 buffer->state = s->state; 17 buffer->return_code = s->return_code; 18 buffer->fail_count = s->fail_count; 19 20 buffer->flags = ((s->stop_timeout != 0) << 4) | 21 ((s->restart == S_ONCE) << 3) | 22 ((s->restart == S_RESTART) << 2) | 23 (s->last_exit << 0); 24 25 buffer->pid[0] = (s->pid >> 0) & 0xff; 26 buffer->pid[1] = (s->pid >> 8) & 0xff; 27 buffer->pid[2] = (s->pid >> 16) & 0xff; 28 buffer->pid[3] = (s->pid >> 24) & 0xff; 29 30 buffer->paused = s->paused; 31 buffer->restart = service_need_restart(s) ? 'u' : 'd'; 32 buffer->force_down = 0; 33 34 switch (s->state) { 35 case STATE_INACTIVE: 36 case STATE_ERROR: 37 case STATE_DONE: 38 buffer->state_runit = 0; // inactive 39 break; 40 case STATE_SETUP: 41 case STATE_STARTING: 42 case STATE_ACTIVE_DUMMY: 43 case STATE_ACTIVE_FOREGROUND: 44 case STATE_ACTIVE_BACKGROUND: 45 case STATE_STOPPING: 46 buffer->state_runit = 1; // running 47 break; 48 case STATE_FINISHING: 49 buffer->state_runit = 2; // finishing 50 break; 51 } 52 }