update to cinit-0.3pre19

Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
This commit is contained in:
Nico Schottelius 2009-11-30 07:27:49 +01:00
commit 7c47ae1c48
1119 changed files with 101885 additions and 0 deletions

View file

@ -0,0 +1,22 @@
This directory contains the server (aka cinit) part of the communication process.
All the communication functions do not depend on the underlying
inter process communication mechanism. Use the following functions:
- send_command(): client function: sends a command to cinit
- send_service(): client function: send the service name to operate on
- read_command(): server function: reads beginning of a command
* Extracts the command
* reads client identification (=pid)
* calls other functions, depending on the command send => switch()
- read_service(): server function: reads service
- write_answer(): server function: answer?
* sends answers to clients => senseful?
TODO:
- define information function, that returns various information about
a service

View file

@ -0,0 +1,45 @@
/*******************************************************************************
*
* 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/>.
*
* disables a service
*
*/
#include "svc-intern.h" /* list_search */
#include "cinit.h" /* structure: cinit_answer */
/**
* Returns the answer to the disable request to the client.
*/
int answer_svc_disable(char *svc, struct cinit_answer *asr)
{
struct listitem *tmp;
tmp = list_search(svc);
if(!tmp) {
asr->ret = CINIT_ASW_SVC_UNKNOWN;
} else {
asr->ret = svc_disable(tmp);
asr->opt = 0;
}
return 1;
}

View file

@ -0,0 +1,42 @@
/*******************************************************************************
*
* 2007-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/>.
*
* return pid of service
*
*/
#include "svc-intern.h" /* VERSION */
#include "cinit.h" /* structure: cinit_answer */
int answer_svc_pid(char *svc, struct cinit_answer *asr)
{
struct listitem *tmp;
tmp = list_search(svc);
if(!tmp) {
asr->ret = CINIT_ASW_SVC_UNKNOWN;
} else {
asr->ret = CINIT_ASW_OK;
asr->opt = tmp->pid;
}
return 1;
}

View file

@ -0,0 +1,43 @@
/*******************************************************************************
*
* 2007-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/>.
*
* returns status of service
*
*/
#include <string.h> /* strncpy */
#include "svc-intern.h" /* VERSION */
#include "cinit.h" /* structure: cinit_answer */
int answer_svc_status(char *svc, struct cinit_answer *asr)
{
struct listitem *tmp;
tmp = list_search(svc);
if(!tmp) {
asr->ret = CINIT_ASW_SVC_UNKNOWN;
} else {
asr->ret = CINIT_ASW_OK;
asr->opt = tmp->status;
}
return 1;
}

View file

@ -0,0 +1,43 @@
/*******************************************************************************
*
* 2007-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/>.
*
* Disable a service (with or without dependencies)
*
*/
#include "cinit.h" /* structure: cinit_answer */
int answer_svc_stop(char *svc, struct cinit_answer *asr)
{
struct listitem *tmp;
tmp = list_search(svc);
if(!tmp) {
asr->ret = CINIT_ASW_SVC_UNKNOWN;
} else {
if(tmp->status & (CINIT_ST_RESPAWNING | CINIT_ST_ONCE_RUN)) {
asr->ret = svc_disable(tmp);
} else { /* not running, nothing todo */
asr->ret = CINIT_ASW_OK;
}
}
return 1;
}

View file

@ -0,0 +1,35 @@
/*******************************************************************************
*
* 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/>.
*
* return version of cinit
*
*/
#include "config.h" /* VERSION */
#include "cinit.h" /* structure: cinit_answer */
int answer_version(struct cinit_answer *asr)
{
asr->ret = CINIT_ASW_OK;
cinit_cp_data(asr->data, VERSION);
return 1;
}

View file

@ -0,0 +1,32 @@
/*******************************************************************************
*
* 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/>.
*
* Append data to the existing field
*
*/
#include <string.h> /* strncpy */
#include "cinit.h" /* CINIT_DATA_LEN */
void cinit_append_data(char data[], char *src)
{
strncat(data, src, CINIT_DATA_LEN);
}

View file

@ -0,0 +1,32 @@
/*******************************************************************************
*
* 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/>.
*
* fill the data field of qsn and asn
*
*/
#include <string.h> /* strncpy */
#include "cinit.h" /* CINIT_DATA_LEN */
void cinit_cp_data(char data[], char *src)
{
strncpy(data, src, CINIT_DATA_LEN);
}

View file

@ -0,0 +1,66 @@
/*******************************************************************************
*
* 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/>.
*
* cinit reads a command sent by a client, called by ipc listener
*
*/
#include "cinit.h" /* structures */
#include "intern.h" /* answer_svc_status() */
int read_command(struct cinit_question qsn, struct cinit_answer *asr)
{
switch (qsn.cmd) {
case CINIT_QSN_GET_VERSION:
if(!answer_version(asr))
return 0;
break;
case CINIT_QSN_GET_STATUS:
if(!answer_svc_status(qsn.data, asr))
return 0;
break;
case CINIT_QSN_GET_PID:
if(!answer_svc_pid(qsn.data, asr))
return 0;
break;
case CINIT_QSN_SVC_DISABLE:
if(!answer_svc_disable(qsn.data, asr))
return 0;
break;
/*
* FIXME: stopped here case CINIT_MSG_SVC_ENABLE:
* if(!answer_svc_enable(qsn.data, asr)) return 0; break;
*/
/*
* Unknown command: should not happen :-)
*/
default:
return 0;
break;
}
return 1;
}