summarylogtreecommitdiffstats
path: root/texmaster-launcher.c.in
blob: 6b9069e6df6ee30092168814f5e26b4a975fe540 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>

#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

char *dir = "/usr/local/games/Texmaster2009-3";

char *nvfile = "Texmaster2009.ubuntu10.04.nv";

char *savfile = "Texmaster2009.ubuntu10.04.sav";

char *texexe = "./Texmaster2009.ubuntu10.04.ARCHSUFFIX";

char *launcherexe = "texmaster-launcher";

mode_t mode =
  S_IRUSR | S_IWUSR |
  S_IRGRP | S_IWGRP |
  S_IROTH;

int fixfile (char *path) {
  if (access (path, F_OK) == 0 && chmod (path, mode) != 0) {
    return -1;
  }
  return 0;
}

int getmygid (gid_t *gid) {
  struct stat buf;
  if (stat (launcherexe, &buf) != 0) {
    return -1;
  }
  *gid = buf.st_gid;
  return 0;
}

int main (void) {
  gid_t gid;
  if (chdir (dir) != 0) {
    fprintf (stderr, "failed to chdir to Texmaster dir\r\n");
    return 1;
  }
  if (getmygid (&gid) != 0) {
    fprintf (stderr, "failed to get group owner\r\n");
    return 1;
  }
  fprintf (stderr, "gid is %d\r\n", gid);
  if (setgid (gid) != 0) {
    fprintf (stderr, "failed to setgid to group owner\r\n");
    return 1;
  }
  if (fixfile (nvfile) != 0) {
    fprintf (stderr, "failed to fix perm for nv file\r\n");
    return 1;
  }
  if (fixfile (savfile) != 0) {
    fprintf (stderr, "failed to fix perm for sav file\r\n");
    return 1;
  }
  execl (texexe, texexe, NULL);
  fprintf (stderr, "failed to exec Texmaster\r\n");
  return 1;
}