66 lines
1.6 KiB
Plaintext
66 lines
1.6 KiB
Plaintext
/*
|
|
* (c) 2005 Nico Schottelius (nico-linux at schottelius.org)
|
|
* change status of a service
|
|
* part of cinit
|
|
*/
|
|
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
|
|
#include "cinit.h"
|
|
|
|
/* one handler for read and write! */
|
|
int do_change_status(char *svc, char *status, pid_t *pid, int sock2, int action)
|
|
{
|
|
char buf = CMD_CHG_STATUS;
|
|
int tmp;
|
|
ssize_t (*fpoint)(int,void* ,size_t);
|
|
|
|
D_PRINTF("VERSUCHE STATUS ZU AENDERN");
|
|
printf("socket: %d (cmd=%d)\n",sock2, buf);
|
|
|
|
if(action == ACT_READ) {
|
|
D_PRINTF("Leeeese");
|
|
fpoint = read;
|
|
} else {
|
|
D_PRINTF("schreibe");
|
|
fpoint = write; /* don't care about warnings! */
|
|
}
|
|
|
|
if(action == ACT_WRITE) {
|
|
D_PRINTF("schreibe kommando");
|
|
if(fpoint(sock2,&buf,1) == -1) { /* COMMAND */
|
|
perror("command i/o");
|
|
return 0;
|
|
}
|
|
tmp = strlen(svc);
|
|
sock2 = connect_sock(sock2);
|
|
}
|
|
|
|
if(fpoint(sock2,&tmp,sizeof(tmp)) == -1) { /* length */
|
|
perror("i/o: length");
|
|
return 0;
|
|
}
|
|
|
|
if(fpoint(sock2,svc,tmp) == -1) { /* write service name */
|
|
perror("i/o: service name");
|
|
return 0;
|
|
}
|
|
|
|
if(fpoint(sock2,status,sizeof(*status)) == -1) { /* status */
|
|
perror("i/o: status");
|
|
printf("Status: %d, *status=%d, sizeof=%d\n",status,*status,sizeof(*status));
|
|
return 0;
|
|
}
|
|
|
|
if(fpoint(sock2,pid,sizeof(*pid)) == -1) { /* PID */
|
|
perror("i/o: PID");
|
|
return 0;
|
|
}
|
|
|
|
D_PRINTF("fertig mit statuswechsel lesen");
|
|
|
|
return 1;
|
|
}
|