7 A Linux/Unix toolset and driver for Nokia mobile phones.
9 Released under the terms of the GNU GPL, see file COPYING for more details.
11 Mgnokiidev gets passed a slave pty name by gnokiid and uses this
12 information to create a symlink from the pty to /dev/gnokii.
23 #include <sys/types.h>
32 int main(int argc, char *argv[])
35 char dev_name[DEVLEN];
37 /* Check we have one and only one command line argument. */
39 fprintf(stderr, "mgnokiidev takes one and only one argument!\n");
43 /* Check if argument has a reasonable length (less than MAXLEN characters) */
44 if (strlen(argv[1]) >= MAXLEN) {
45 fprintf(stderr, "Argument must be less than %d characters.\n", MAXLEN);
49 strncpy(dev_name, argv[1], DEVLEN);
51 /* Check for suspicious characters. */
52 for (count = 0; count < strlen(dev_name); count ++)
53 if (!(isalnum(dev_name[count]) || dev_name[count]=='/')) {
54 fprintf(stderr, "Suspicious character at index %d in argument.\n", count);
61 /* Change group of slave pty to group of mgnokiidev */
62 err = chown(dev_name, -1, getgid());
65 perror("mgnokiidev - chown: ");
69 /* Change permissions to rw by group */
70 err = chmod(dev_name, S_IRGRP | S_IWGRP | S_IRUSR | S_IWUSR);
73 perror("mgnokiidev - chmod: ");
77 /* FIXME: Possible bug - should check that /dev/gnokii doesn't already exist
78 in case multiple users are trying to run gnokii. Well, but will be
79 mgnokiidev called then? I do not think so - you will probably got the
80 message serialport in use or similar. Don't you. I haven't tested it
83 /* Remove symlink in case it already exists. Don't care if it fails. */
84 unlink ("/dev/gnokii");
87 err = symlink(dev_name, "/dev/gnokii");
90 perror("mgnokiidev - symlink: ");