collect.c revision 912541b0246ef315d4d851237483b98c9dd3f992
/*
* Collect variables across events.
*
* usage: collect [--add|--remove] <checkpoint> <id> <idlist>
*
* Adds ID <id> to the list governed by <checkpoint>.
* <id> must be part of the ID list <idlist>.
* If all IDs given by <idlist> are listed (ie collect has been
* invoked for each ID in <idlist>) collect returns 0, the
* number of missing IDs otherwise.
* A negative number is returned on error.
*
* Copyright(C) 2007, Hannes Reinecke <hare@suse.de>
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <getopt.h>
#include "libudev.h"
#include "libudev-private.h"
#define BUFSIZE 16
#define UDEV_ALARM_TIMEOUT 180
enum collect_state {
};
struct _mate {
struct udev_list_node node;
char *name;
enum collect_state state;
};
static struct udev_list_node bunch;
static int debug;
/* This can increase dynamically */
{
char *mate;
}
{
exit(4);
}
static void usage(void)
{
printf("usage: collect [--add|--remove] [--debug] <checkpoint> <id> <idlist>\n"
"\n"
" Adds ID <id> to the list governed by <checkpoint>.\n"
" <id> must be part of the list <idlist>.\n"
" If all IDs given by <idlist> are listed (ie collect has been\n"
" invoked for each ID in <idlist>) collect returns 0, the\n"
" number of missing IDs otherwise.\n"
" On error a negative number is returned.\n"
"\n");
}
/*
* prepare
*
* Prepares the database file
*/
{
char buf[512];
int fd;
if (fd < 0)
if (debug)
if (debug)
} else {
if (debug)
}
}
return fd;
}
/*
* Read checkpoint file
*
* Tricky reading this. We allocate a buffer twice as large
* as we're going to read. Then we read into the upper half
* of that buffer and start parsing.
* Once we do _not_ find end-of-work terminator (whitespace
* character) we move the upper half to the lower half,
* adjust the read pointer and read the next bit.
* Quite clever methinks :-)
* I should become a programmer ...
*
* Yes, one could have used fgets() for this. But then we'd
* have to use freopen etc which I found quite tedious.
*/
{
int len;
if (!buf) {
return -1;
}
if (debug)
goto restart;
}
if (ptr) {
*ptr = '\0';
ptr++;
continue;
if (debug)
}
}
if (!ptr)
if (!ptr)
break;
}
return 0;
}
/*
* invite
*
* Adds a new ID 'us' to the internal list,
* marks it as confirmed.
*/
{
struct udev_list_node *him_node;
if (debug)
}
}
}
/*
* reject
*
* Marks the ID 'us' as invalid,
* causing it to be removed when the
* list is written out.
*/
{
struct udev_list_node *him_node;
if (debug)
}
}
}
/*
* kickout
*
* Remove all IDs in the internal list which are not part
* of the list passed via the commandline.
*/
static void kickout(void)
{
struct udev_list_node *him_node;
struct udev_list_node *tmp;
}
}
}
/*
* missing
*
* Counts all missing IDs in the internal list.
*/
{
char *buf;
int ret = 0;
struct udev_list_node *him_node;
if (!buf)
return -1;
ret++;
} else {
char *tmpbuf;
if (!tmpbuf) {
return -1;
}
}
}
}
return ret;
}
/*
* everybody
*
* Prints out the status of the internal list.
*/
static void everybody(void)
{
struct udev_list_node *him_node;
const char *state = "";
case STATE_NONE:
state = "none";
break;
case STATE_OLD:
state = "old";
break;
case STATE_CONFIRMED:
state = "confirmed";
break;
}
}
}
{
{}
};
int argi;
char *checkpoint, *us;
int fd;
int i;
int ret = EXIT_SUCCESS;
int prune = 0;
char tmpdir[UTIL_PATH_SIZE];
ret = EXIT_FAILURE;
goto exit;
}
while (1) {
int option;
if (option == -1)
break;
switch (option) {
case 'a':
prune = 0;
break;
case 'r':
prune = 1;
break;
case 'd':
debug = 1;
break;
case 'h':
usage();
goto exit;
default:
ret = 1;
goto exit;
}
}
printf("Missing parameter(s)\n");
ret = 1;
goto exit;
}
ret = 2;
goto exit;
}
if (debug)
if (fd < 0) {
ret = 3;
goto out;
}
ret = 2;
goto out;
}
struct udev_list_node *him_node;
}
if (!who) {
if (debug)
} else {
if (debug)
}
}
if (prune)
else
if (debug) {
everybody();
}
kickout();
out:
if (debug)
everybody();
if (ret >= 0)
exit:
return ret;
}