/* * Copyright (C) 1999 by Manfred Spraul. * * Redistribution of this file is permitted under the terms of the GNU * General Public License (GPL) * $Header: /home/manfred/cvs-tree/manfred/ipcsem/dec.c,v 1.5 2003/06/17 16:16:55 manfred Exp $ */ #include #include #include #include #include #include #include #include #define TRUE 1 #define FALSE 0 union semun { int val; struct semid_ds *buf; unsigned short int *array; struct seminfo* __buf; }; int main(int argc,char** argv) { int id; int key; int res; int *nr; int *val; int i; int sems; printf("change [...]\n"); if(argc < 4 || ((argc % 2) == 1)) { printf("Invalid parameters.\n"); return 1; } key = atoi(argv[1]); if(key == 0) { printf("Invalid parameters: Key invalid.\n"); return 1; } if (key > 0) { id = semget(key,1,0); if(id == -1) { printf(" findkey() failed.\n"); return 1; } } else { id = -key; printf(" findkey() bypassed, using id %d.\n", id); } sems = (argc-2)/2; nr=(int*)malloc(sizeof(int)*sems); val=(int*)malloc(sizeof(int)*sems); if (!nr || !val) { printf("Malloc failed.\n"); return 1; } printf("pid %d: changing %d semaphores:\n",getpid(), sems); for (i=0;i