update to cinit-0.3pre19
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
This commit is contained in:
parent
367a74c75e
commit
7c47ae1c48
1119 changed files with 101885 additions and 0 deletions
|
|
@ -0,0 +1,2 @@
|
|||
This implementation uses the new realtime inferface of
|
||||
posix instead of the old one functions.
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/***********************************************************************
|
||||
*
|
||||
* 2007 Nico Schottelius (nico-cinit schottelius.org)
|
||||
*
|
||||
* part of cLinux/cinit
|
||||
*
|
||||
* Create new queues: One for recieving, one for sending
|
||||
*
|
||||
*/
|
||||
|
||||
#include <mqueue.h>
|
||||
|
||||
#include "cinit.h"
|
||||
#include "config.h"
|
||||
#include "msgq-rt.h"
|
||||
|
||||
int cinit_ipc_init(void)
|
||||
{
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#include <mqueue.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
mqd_t readq = mq_open("/test",O_RDWR|O_CREAT|O_EXCL);
|
||||
//mqd_t readq = mq_open("/bin/ls",O_RDWR|O_CREAT|O_EXCL);
|
||||
|
||||
if(readq == -1) {
|
||||
perror("oh nein");
|
||||
return 1;
|
||||
}
|
||||
mqd_t writeq = mq_open("/bin/cp",O_WRONLY|O_CREAT|O_EXCL);
|
||||
if(readq == -1) {
|
||||
perror("oh oh nein");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/***********************************************************************
|
||||
*
|
||||
* 2007 Nico Schottelius (nico-cinit schottelius.org)
|
||||
*
|
||||
* part of cLinux/cinit
|
||||
*
|
||||
* Create new queues: One for recieving, one for sending
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CINIT_IPC_HEADER
|
||||
#define CINIT_IPC_HEADER
|
||||
|
||||
#define MSGQ_PATHNAME "/cinit" /* identifier */
|
||||
|
||||
/***********************************************************************
|
||||
* structures
|
||||
*/
|
||||
|
||||
/* messages _from_ the client _to_ the server */
|
||||
struct msgq_client {
|
||||
long mtype;
|
||||
pid_t pid;
|
||||
struct msg_client msg;
|
||||
};
|
||||
|
||||
/* messages _from_ the server _to_ the client */
|
||||
struct msgq_server_short {
|
||||
long mtype;
|
||||
struct asw_sstatus answer;
|
||||
};
|
||||
|
||||
/***********************************************************************
|
||||
* Messages
|
||||
*/
|
||||
|
||||
#define MSG_MSGQ_DESTROY "msgq-destroy"
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
cinit/src/ipc/msgq: About this msqg implementation
|
||||
===================================================
|
||||
Nico Schottelius <nico-linux-cinit__@__schottelius.org>
|
||||
0.1, Initial Version from 2006-08-04
|
||||
:Author Initials: NS
|
||||
|
||||
Intro here
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
cinit opens a
|
||||
|
||||
Files
|
||||
-----
|
||||
- README.text: This file
|
||||
- cinit_init_ipc.c: Init
|
||||
msgq.h
|
||||
objects
|
||||
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/***********************************************************************
|
||||
*
|
||||
* 2007 Nico Schottelius (nico-cinit schottelius.org)
|
||||
*
|
||||
* part of cLinux/cinit
|
||||
*
|
||||
* Client reads messages from cinit
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/msg.h> /* msg* */
|
||||
#include <string.h> /* memcpy() */
|
||||
#include <unistd.h> /* getpid() */
|
||||
#include "intern.h" /* print_errno */
|
||||
#include "msgq.h" /* msq specific */
|
||||
|
||||
int cinit_ipc_cread(struct cinit_answer *buf)
|
||||
{
|
||||
struct cinit_msgq_server asr;
|
||||
|
||||
if(msgrcv(__cinit_mq_in, &asr, sizeof(asr.asr), getpid(), 0) == -1) {
|
||||
print_errno(__CINIT_MSG_MSGQ_MSGRCV);
|
||||
return 0;
|
||||
}
|
||||
memcpy(buf, &(asr.asr), sizeof(*buf));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/***********************************************************************
|
||||
*
|
||||
* 2007 Nico Schottelius (nico-cinit schottelius.org)
|
||||
*
|
||||
* part of cLinux/cinit
|
||||
*
|
||||
* Client sends messages to cinit
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/msg.h> /* msgget */
|
||||
#include <string.h> /* memcpy() */
|
||||
#include "intern.h" /* print_errno */
|
||||
#include "msgq.h" /* structure */
|
||||
|
||||
int cinit_ipc_csend(struct cinit_question *qsn)
|
||||
{
|
||||
struct cinit_msgq_client msg;
|
||||
|
||||
msg.mtype = 1; /* cinit = 1 */
|
||||
|
||||
/* copy question structure into the msgq-structure */
|
||||
memcpy(&(msg.qsn), qsn, sizeof(msg.qsn));
|
||||
|
||||
if(msgsnd(__cinit_mq_out, &msg, sizeof(msg.qsn), 0) == -1) {
|
||||
print_errno(__CINIT_MSG_MSGQ_MSGSEND);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/***********************************************************************
|
||||
*
|
||||
* 2006-2007 Nico Schottelius (nico-cinit schottelius.org)
|
||||
*
|
||||
* part of cLinux/cinit
|
||||
*
|
||||
* Destory ipc mechanism, cinit is gonna die soon.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/msg.h> /* msgget */
|
||||
#include <stdio.h> /* NULL */
|
||||
#include "msgq.h" /* mq_in, mq_out */
|
||||
#include "intern.h" /* print_errno */
|
||||
|
||||
void cinit_ipc_destroy(void)
|
||||
{
|
||||
if(msgctl(__cinit_mq_in, IPC_RMID, NULL) == -1) {
|
||||
print_errno(__CINIT_MSG_MSGQ_DESTROY); /* print warning, continue */
|
||||
}
|
||||
if(msgctl(__cinit_mq_out, IPC_RMID, NULL) == -1) {
|
||||
print_errno(__CINIT_MSG_MSGQ_DESTROY); /* print warning, continue */
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/***********************************************************************
|
||||
*
|
||||
* 2006-2007 Nico Schottelius (nico-cinit schottelius.org)
|
||||
*
|
||||
* part of cLinux/cinit
|
||||
*
|
||||
* Create new queues: One for recieving, one for sending
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/ipc.h> /* ftok */
|
||||
#include <sys/msg.h> /* msgget */
|
||||
#include "intern.h" /* print_errno */
|
||||
#include "msgq.h" /* message queue */
|
||||
|
||||
int cinit_ipc_init(void)
|
||||
{
|
||||
key_t k_tmp;
|
||||
|
||||
/* to_server */
|
||||
k_tmp = ftok(__CINIT_MSGQ_PATHNAME, __CINIT_MSGQ_TO_SERVER);
|
||||
if(k_tmp == -1) {
|
||||
print_errno(__CINIT_MSG_MSGQ_FTOK);
|
||||
return 0;
|
||||
}
|
||||
__cinit_mq_in = msgget(k_tmp, __CINIT_MSGQ_PERMS | IPC_CREAT);
|
||||
if(__cinit_mq_in == -1) {
|
||||
print_errno(__CINIT_MSG_MSGQ_MSGGET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
k_tmp = ftok(__CINIT_MSGQ_PATHNAME, __CINIT_MSGQ_TO_CLIENT);
|
||||
if(k_tmp == -1) {
|
||||
print_errno(__CINIT_MSG_MSGQ_FTOK);
|
||||
return 0;
|
||||
}
|
||||
__cinit_mq_out = msgget(k_tmp, __CINIT_MSGQ_PERMS | IPC_CREAT);
|
||||
if(__cinit_mq_out == -1) {
|
||||
print_errno(__CINIT_MSG_MSGQ_MSGGET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* 2006-2008 Nico Schottelius (nico-cinit at schottelius.org)
|
||||
*
|
||||
* This file is part of cinit.
|
||||
|
||||
* cinit is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* cinit is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with cinit. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
* Listen to messages
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h> /* printf() */
|
||||
|
||||
#include <sys/msg.h> /* msg* */
|
||||
#include <errno.h> /* errno */
|
||||
|
||||
#include "intern.h" /* print_errno */
|
||||
#include "msgq.h" /* structs */
|
||||
|
||||
int cinit_ipc_listen(void)
|
||||
{
|
||||
int tmp;
|
||||
struct cinit_msgq_client qsn;
|
||||
struct cinit_msgq_server asr;
|
||||
struct msqid_ds msq;
|
||||
|
||||
tmp = msgrcv(__cinit_mq_in, &qsn, sizeof (qsn.qsn), 0, 0);
|
||||
|
||||
/* message system problem */
|
||||
if(tmp == -1) {
|
||||
if(errno != EINTR) {
|
||||
print_errno(__CINIT_MSG_MSGQ_MSGRCV);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* retrieve pid */
|
||||
if(msgctl(__cinit_mq_in, IPC_STAT, &msq) == -1) {
|
||||
print_errno(__CINIT_MSG_MSGQ_MSGCTL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!read_command(qsn.qsn, &(asr.asr))) {
|
||||
/* FIXME: mini_print */
|
||||
printf("read command failed\n");
|
||||
|
||||
asr.asr.ret = CINIT_ASW_ERR_INTERN;
|
||||
}
|
||||
|
||||
asr.mtype = msq.msg_lspid;
|
||||
if(msgsnd(__cinit_mq_out, &asr, sizeof(asr.asr), 0) == -1) {
|
||||
/* FIXME: do different things on differen errnos ... */
|
||||
print_errno("msgsend/answer");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
/***********************************************************************
|
||||
*
|
||||
* 2007 Nico Schottelius (nico-cinit schottelius.org)
|
||||
*
|
||||
* part of cLinux/cinit
|
||||
*
|
||||
* Disconnect from cinit
|
||||
*
|
||||
*/
|
||||
|
||||
int cinit_ipc_logoff(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
/***********************************************************************
|
||||
*
|
||||
* 2006-2007 Nico Schottelius (nico-cinit schottelius.org)
|
||||
*
|
||||
* part of cLinux/cinit
|
||||
*
|
||||
* Listen to messages
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/ipc.h> /* ftok */
|
||||
#include <sys/msg.h> /* msgget */
|
||||
#include "intern.h" /* print_errno */
|
||||
#include "msgq.h" /* msgq constants */
|
||||
|
||||
int cinit_ipc_logon(void)
|
||||
{
|
||||
key_t k_tmp;
|
||||
|
||||
/* generiere nen schluessel: andersrum als im Server */
|
||||
k_tmp = ftok(__CINIT_MSGQ_PATHNAME, __CINIT_MSGQ_TO_CLIENT);
|
||||
if(k_tmp == -1) {
|
||||
print_errno(__CINIT_MSG_MSGQ_FTOK);
|
||||
return 0;
|
||||
}
|
||||
__cinit_mq_in = msgget(k_tmp, 0);
|
||||
if(__cinit_mq_in == -1) {
|
||||
print_errno(__CINIT_MSG_MSGQ_MSGGET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
k_tmp = ftok(__CINIT_MSGQ_PATHNAME, __CINIT_MSGQ_TO_SERVER);
|
||||
if(k_tmp == -1) {
|
||||
print_errno(__CINIT_MSG_MSGQ_FTOK);
|
||||
return 0;
|
||||
}
|
||||
__cinit_mq_out = msgget(k_tmp, 0);
|
||||
if(__cinit_mq_out == -1) {
|
||||
print_errno(__CINIT_MSG_MSGQ_MSGGET);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/***********************************************************************
|
||||
*
|
||||
* 2006-2007 Nico Schottelius (nico-cinit //@\\ schottelius.org)
|
||||
*
|
||||
* part of cLinux/cinit
|
||||
*
|
||||
* header of message queuing interface
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __CINIT_IPC_HEADER
|
||||
#define __CINIT_IPC_HEADER
|
||||
|
||||
#include <cinit.h> /* structures */
|
||||
|
||||
/***********************************************************************
|
||||
* configuration
|
||||
*/
|
||||
|
||||
#define __CINIT_MSGQ_PATHNAME "/bin/sh" /* should be on every *nix */
|
||||
#define __CINIT_MSGQ_TO_SERVER 'i' /* also for ftok */
|
||||
#define __CINIT_MSGQ_TO_CLIENT 'o' /* also for ftok */
|
||||
#define __CINIT_MSGQ_PERMS 0660 /* queue permissions */
|
||||
|
||||
/***********************************************************************
|
||||
* global variables: FIXME: rename, we're in client namespace!
|
||||
*/
|
||||
int __cinit_mq_in; /* input */
|
||||
int __cinit_mq_out; /* output */
|
||||
|
||||
/***********************************************************************
|
||||
* structures
|
||||
*/
|
||||
|
||||
/* messages _from_ the client _to_ the server */
|
||||
struct cinit_msgq_client {
|
||||
long mtype;
|
||||
struct cinit_question qsn;
|
||||
};
|
||||
|
||||
/* messages _from_ the server _to_ the client */
|
||||
struct cinit_msgq_server {
|
||||
long mtype;
|
||||
struct cinit_answer asr;
|
||||
};
|
||||
|
||||
/***********************************************************************
|
||||
* Messages
|
||||
*/
|
||||
|
||||
#define __CINIT_MSG_MSGQ_FTOK "ftok"
|
||||
#define __CINIT_MSG_MSGQ_MSGGET "msgget"
|
||||
#define __CINIT_MSG_MSGQ_MSGCTL "msgctl"
|
||||
#define __CINIT_MSG_MSGQ_MSGSEND "msgsend"
|
||||
#define __CINIT_MSG_MSGQ_MSGRCV "msgrcv"
|
||||
#define __CINIT_MSG_MSGQ_DESTROY "msgq-destroy"
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
ipc/current/cinit_ipc_init.o
|
||||
ipc/current/cinit_ipc_listen.o
|
||||
ipc/current/cinit_ipc_sclose.o
|
||||
ipc/current/cinit_ipc_destroy.o
|
||||
ipc/current/cinit_ipc_logon.o
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* (c) 2005 Nico Schottelius (nico-linux at schottelius.org)
|
||||
* tell cinit that I want to start a service
|
||||
* part of cinit
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include "cinit.h"
|
||||
|
||||
int begin_msg(char cmd)
|
||||
{
|
||||
sock = connect_sock(sock);
|
||||
if( sock == -1 ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(write(sock,&cmd,sizeof(cmd)) == -1) {
|
||||
perror(MSG_ERR_IO);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* (c) 2005, 2006 Nico Schottelius (nico-linux at schottelius.org)
|
||||
* cinit.c
|
||||
* part of cLinux/cinit
|
||||
*/
|
||||
|
||||
/* *stat() */
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* open */
|
||||
#include <fcntl.h>
|
||||
|
||||
/* siggnal */
|
||||
#include <signal.h>
|
||||
|
||||
/* PATH_MAX */
|
||||
#include <limits.h>
|
||||
|
||||
/* str* */
|
||||
#include <string.h>
|
||||
|
||||
/* sockets */
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "cinit.h"
|
||||
|
||||
/***********************************************************************
|
||||
* create a socket, when we recieved a signal
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct sockaddr_un addr;
|
||||
struct pollfd plist;
|
||||
char *initdir;
|
||||
|
||||
list = NULL; /* list of services is empty currently */
|
||||
initdir = CINIT_INIT; /* default init dir */
|
||||
|
||||
cpid = getpid();
|
||||
if(cpid != 1) {
|
||||
usage(MSG_USAGE,MSG_NOT_ONE);
|
||||
}
|
||||
|
||||
set_signals(ACT_SERV); /* set signal handlers */
|
||||
|
||||
/* read args, profile support */
|
||||
while(argc > 1) {
|
||||
if( !strncmp(PROFILE, argv[argc-1], strlen(PROFILE)) ) {
|
||||
initdir = (char *) malloc(
|
||||
strlen(CINIT_DIR) +
|
||||
strlen(&argv[argc-1][strlen(PROFILE)]) + 2
|
||||
);
|
||||
if(initdir == NULL) {
|
||||
panic();
|
||||
}
|
||||
strcpy(initdir,CINIT_DIR);
|
||||
strcat(initdir,SLASH);
|
||||
strcat(initdir,&argv[argc-1][strlen(PROFILE)]);
|
||||
break;
|
||||
}
|
||||
argc--;
|
||||
}
|
||||
|
||||
/* tell the world we are there FIXME: do we really need three calls? */
|
||||
mini_printf(MSG_CINIT,1); mini_printf(initdir,1); mini_printf("\n",1);
|
||||
|
||||
if( chdir(CINIT_INIT) == -1) {
|
||||
perror(MSG_CHDIR);
|
||||
panic();
|
||||
}
|
||||
|
||||
/******************** TMPDIR **********************/
|
||||
if( mount(C_TMPMOUNT,CINIT_TMNT,C_TMPFS,0,NULL) == -1 ) {
|
||||
perror(MSG_ERR_MOUNT);
|
||||
panic();
|
||||
}
|
||||
|
||||
/******************** begin socket **********************/
|
||||
sock = socket(AF_UNIX,SOCK_STREAM,0); /* create socket */
|
||||
if( sock == -1 ) {
|
||||
perror(MSG_SOCKET);
|
||||
panic();
|
||||
}
|
||||
|
||||
memset(&addr, 0, sizeof(addr) ); /* clear addr */
|
||||
strcpy(addr.sun_path, CINIT_SOCK);
|
||||
addr.sun_family = AF_UNIX;
|
||||
|
||||
if(bind(sock,(struct sockaddr *)&addr,sizeof(addr)) == -1) {
|
||||
perror(MSG_BIND);
|
||||
panic();
|
||||
}
|
||||
|
||||
/* start listening */
|
||||
if(listen(sock,SOCK_QUEUE) == -1) {
|
||||
perror(MSG_LISTEN);
|
||||
panic();
|
||||
}
|
||||
|
||||
/* start init or profile */
|
||||
run_init_svc(initdir);
|
||||
|
||||
/* free, if we malloc()ed before */
|
||||
if(initdir != CINIT_INIT) {
|
||||
free(initdir);
|
||||
}
|
||||
|
||||
/* our life is polling a socket */
|
||||
plist.fd = sock;
|
||||
plist.events = POLLIN | POLLPRI;
|
||||
while(1) {
|
||||
if(poll(&plist, 1, -1) != -1) {
|
||||
if( (plist.revents & POLLIN) == POLLIN ||
|
||||
(plist.revents & POLLPRI) == POLLPRI) {
|
||||
sigio(sock);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* cinit
|
||||
* (c) 2005 Nico Schottelius (nico-linux at schottelius.org)
|
||||
* handle client requests
|
||||
*/
|
||||
|
||||
#include <sys/wait.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "cinit.h"
|
||||
|
||||
/***********************************************************************
|
||||
* sigio: client handling
|
||||
*/
|
||||
|
||||
/* we are called, if one or _more_ connections are waiting */
|
||||
void sigio(int socket)
|
||||
{
|
||||
int tmp, nsock;
|
||||
char buf[PATH_MAX+1], status;
|
||||
struct listitem *list_tmp;
|
||||
pid_t pid;
|
||||
|
||||
while ( (nsock = accept(socket,(struct sockaddr *) NULL,
|
||||
(socklen_t *) NULL)) != -1) {
|
||||
|
||||
if( read(nsock,&buf[0],1) == -1) {
|
||||
perror(MSG_ERR_READ);
|
||||
close(nsock);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(buf[0]) {
|
||||
|
||||
/********************** START SERVICE *******************/
|
||||
case CMD_START_SVC:
|
||||
tmp = do_svc_name(nsock,buf,ACT_SERV);
|
||||
if(!tmp) break;
|
||||
|
||||
buf[tmp] = 0;
|
||||
list_tmp = list_search(buf);
|
||||
|
||||
if(list_tmp != NULL) { /* service already exists, return status */
|
||||
status = list_tmp->status;
|
||||
do_result(nsock,&status);
|
||||
break;
|
||||
}
|
||||
|
||||
tmp = list_insert(buf,ST_TMP); /* add service */
|
||||
if(!tmp) { /* failed */
|
||||
LOG(MSG_ERR_ADD_SVC);
|
||||
status = ST_FAIL;
|
||||
} else {
|
||||
status = RT_TMPNOW;
|
||||
}
|
||||
do_result(nsock,&status);
|
||||
break;
|
||||
|
||||
/********************** STOP (RESPAWNING) *******************/
|
||||
case CMD_STOP_SVC:
|
||||
tmp = do_svc_name(nsock,buf,ACT_SERV);
|
||||
if(!tmp) break;
|
||||
buf[tmp] = 0;
|
||||
list_tmp = list_search(buf);
|
||||
|
||||
/* FIXME:
|
||||
- handle off
|
||||
- handle switching off once services
|
||||
- perhaps remove old cinit code, which has respawing childs
|
||||
*/
|
||||
|
||||
if(list_tmp != NULL) { /* service exists */
|
||||
if(list_tmp->status == ST_RESPAWN) {
|
||||
/* kill cinit watcher, which kills the real process */
|
||||
kill(list_tmp->pid,SIGTERM);
|
||||
|
||||
/* wait for watcher to terminate */
|
||||
waitpid(list_tmp->pid,&tmp,0);
|
||||
}
|
||||
|
||||
status = ST_OFF;
|
||||
if(!list_modify(buf,status,list_tmp->pid)) {
|
||||
status = ST_FAIL;
|
||||
} else { /* return status */
|
||||
status = list_tmp->status;
|
||||
}
|
||||
} else { /* no service there */
|
||||
status = RT_NOTEXIST;
|
||||
}
|
||||
do_result(nsock,&status);
|
||||
break;
|
||||
|
||||
/********************** CHANGE SERVICE STATUS *******************/
|
||||
case CMD_CHG_STATUS:
|
||||
tmp = do_change_status(buf,&status,&pid,nsock,ACT_SERV);
|
||||
if(!tmp) break;
|
||||
buf[tmp] = 0; /* terminate buf */
|
||||
|
||||
if(!list_modify(buf,status,pid)) {
|
||||
SERVICE_LOG(buf,MSG_ERR_MODIFY);
|
||||
status = 0;
|
||||
}
|
||||
do_result(nsock,&status);
|
||||
break;
|
||||
|
||||
/********************** SPECIAL ACTIONS *******************/
|
||||
case CMD_REBOOT:
|
||||
sig_reboot(SIGHUP);
|
||||
break;
|
||||
case CMD_POWEROFF:
|
||||
sig_reboot(SIGTERM);
|
||||
break;
|
||||
case CMD_HALT:
|
||||
sig_reboot(SIGUSR1);
|
||||
break;
|
||||
case CMD_RESCUE:
|
||||
sig_reboot(SIGUSR2);
|
||||
break;
|
||||
case CMD_UPDATE:
|
||||
sig_reboot(SIGCONT);
|
||||
break;
|
||||
default:
|
||||
LOG(MSG_CMD_UNKNOWN);
|
||||
break;
|
||||
}
|
||||
close(nsock);
|
||||
}
|
||||
|
||||
/* hier kommt man haeufiger herein, interrupted system call */
|
||||
if( errno != EAGAIN && errno != EINTR) { /* report, but don't panic */
|
||||
perror(MSG_ERR_ACCEPT);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* (c) 2005 Nico Schottelius (nico-linux at schottelius.org)
|
||||
* run_svc
|
||||
* part of cinit
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h> /* memset, strcpy */
|
||||
|
||||
#include "cinit.h"
|
||||
|
||||
/* open socket connection to cinit-serv and close original socket */
|
||||
int connect_sock(int socke)
|
||||
{
|
||||
int nsock;
|
||||
struct sockaddr_un addr;
|
||||
|
||||
close(socke);
|
||||
|
||||
nsock = socket(PF_UNIX,SOCK_STREAM,0);
|
||||
if( nsock == -1 ) {
|
||||
perror(MSG_SOCKET);
|
||||
return -1;
|
||||
}
|
||||
socke = sizeof(addr);
|
||||
memset(&addr,0,socke);
|
||||
strcpy(addr.sun_path, CINIT_SOCK);
|
||||
addr.sun_family = AF_UNIX;
|
||||
|
||||
if(connect(nsock,(struct sockaddr *)&addr,socke) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return nsock;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue