postnote.c 430 B

1234567891011121314151617181920212223242526272829303132
  1. #include <u.h>
  2. #include <libc.h>
  3. int
  4. postnote(int group, int pid, char *note)
  5. {
  6. char file[128];
  7. int f, r;
  8. switch(group) {
  9. case PNPROC:
  10. sprint(file, "/proc/%d/note", pid);
  11. break;
  12. case PNGROUP:
  13. sprint(file, "/proc/%d/notepg", pid);
  14. break;
  15. default:
  16. return -1;
  17. }
  18. f = open(file, OWRITE);
  19. if(f < 0)
  20. return -1;
  21. r = strlen(note);
  22. if(write(f, note, r) != r) {
  23. close(f);
  24. return -1;
  25. }
  26. close(f);
  27. return 0;
  28. }