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

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/ipc.h>
  6. #include <sys/msg.h>
  7. #define CONFIG_KERNELD
  8. #include <linux/kerneld.h>
  9.  
  10. #define MSIZE 1024
  11. #define KERNELD_SOUND 300
  12.  
  13. /*
  14.  * Copyright (C) 1995, 1996  Bjorn Ekwall <bj0rn@blox.se>
  15.  *
  16.  * See the file "COPYING" for your rights (GPL).
  17.  *
  18.  * This is an extra kerneld that just listens for sound requests,
  19.  * i.e. message type 300.
  20.  * This number was randomly chosen, as being a round number > 255.
  21.  *
  22.  * That means that it can run concurrently with the "normal" kerneld,
  23.  * so that we can test the funtionality before folding it in with
  24.  * the other kerneld requests.
  25.  *
  26.  * Start "kdsound" as: "/sbin/kdsound &"
  27.  */
  28.  
  29. int
  30. main(argc, argv)
  31. int argc;
  32. char **argv;
  33. {
  34.     struct kerneld_msg *msgp;
  35.     int status;
  36.     int qid;
  37.     char *soundparam;
  38.  
  39.     qid = msgget(IPC_PRIVATE, 0600 | IPC_KERNELD);
  40.     if (qid < 0) {
  41.         perror("kdsound");
  42.         exit(1);
  43.     }
  44.  
  45.     msgp = (struct kerneld_msg *)malloc(sizeof(struct kerneld_msg) + MSIZE);
  46.  
  47.     while (1) {
  48.         status = msgrcv(qid, (struct msgbuf *)msgp,
  49.             sizeof(long) + MSIZE, KERNELD_SOUND, MSG_NOERROR);
  50.         if (status > 0) {
  51. #ifdef NEW_KERNELD_PROTOCOL /* using new extended kerneld message format */
  52.             struct oldkerneld_msg {
  53.                 long mtype;
  54.                 long id;
  55.                 char text[1];
  56.             };
  57.  
  58.             if (msgp->version == 2) {
  59.                 if (msgp->pid != 0) {
  60.                     char triggerpid[30];
  61.                     sprintf(triggerpid, "KERNELD_TRIGGER=%d", msgp->pid);
  62.                     putenv(triggerpid);
  63.                 }
  64.                 soundparam = msgp->text;
  65.             }
  66.             else
  67.                 soundparam = ((struct oldkerneld_msg *)msgp)->text;
  68. #else
  69.             soundparam = msgp->text;
  70. #endif
  71.             if (sound_pid > 0) {
  72.                 kill(
  73.             }
  74.             if ((sound_pid = fork()) == 0) {
  75.                 execlp("/bin/sh", "sh", "/sbin/do_sound",
  76.                     soundparam, 0);
  77.                 exit(0);
  78.             }
  79.         }
  80.     }
  81. }
  82.