home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 May / pcp151c.iso / misc / src / install / modutils / kerneld / kdstat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-06  |  1.7 KB  |  87 lines

  1. #define CONFIG_KERNELD
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <sys/types.h>
  6. #include <sys/ipc.h>
  7. #include <sys/msg.h>
  8. #include <linux/kerneld.h>
  9.  
  10. #define MSIZE 1024
  11. #define MAXCMD 255 /* as in kerneld.c */
  12.  
  13. /*
  14.  * Copyright (C) 1995, Bjorn Ekwall <bj0rn@blox.se>
  15.  *
  16.  * See the file "COPYING" for your rights.
  17.  *
  18.  * This is just used to debug kerneld...
  19.  * Show (and change) the internal kerneld state
  20.  *
  21.  * use as:
  22.  *    kdstat            for just a status
  23.  *    kdstat debug        for debugging on and off
  24.  *    kdstat nodebug
  25.  *    kdstat keep        for autoclean
  26.  *    kdstat nokeep
  27.  *    kdstat delay=10        for changing the timer interval
  28.  *    kdstat flush        flush the IPC message queue
  29.  */
  30.  
  31. #define REPLY_ID 1024
  32.  
  33. #ifndef KDHDR
  34. # ifdef NEW_KERNELD_PROTOCOL
  35. #  define KDHDR (sizeof(long) + sizeof(short) + sizeof(short))
  36. # else
  37. #  define KDHDR sizeof(long)
  38. # endif
  39. #endif
  40.  
  41. int
  42. main(argc, argv)
  43. int argc;
  44. char **argv;
  45. {
  46.     struct kerneld_msg *msgp;
  47.     int qid;
  48.     int status;
  49.     int reply;
  50.  
  51.     qid = msgget(IPC_PRIVATE, 0600 | IPC_KERNELD);
  52.     if (qid < 0) {
  53.         perror("kdsend");
  54.         exit(1);
  55.     }
  56.  
  57.     msgp = (struct kerneld_msg *)malloc(sizeof(struct kerneld_msg) + MSIZE);
  58. #ifdef NEW_KERNELD_PROTOCOL
  59.     msgp->version = 2;
  60.     msgp->pid = getpid();
  61. #endif
  62.  
  63.  
  64.     msgp->mtype = MAXCMD; /* magic! */
  65.     reply = msgp->id = REPLY_ID + getpid();
  66.     if (argc > 1)
  67.         strcpy(msgp->text, argv[1]);
  68.     else
  69.         msgp->text[0] = '\0';
  70.  
  71.     status = msgsnd(qid, (struct msgbuf *)msgp, KDHDR + strlen(msgp->text), 0);
  72.     if (status < 0)
  73.         perror("kdstat");
  74.  
  75.     status = msgrcv(qid, (struct msgbuf *)msgp,
  76.             KDHDR + MSIZE, reply, MSG_NOERROR);
  77.     if (status > 0) {
  78.         msgp->text[status - KDHDR] = '\0';
  79.         printf("%s", msgp->text);
  80.     }
  81.     else if (status < 0)
  82.         perror("kdstat");
  83.     else
  84.         printf("nothing recieved\n");
  85.     return status;
  86. }
  87.