7 A Linux/Unix toolset and driver for Nokia mobile phones.
9 Copyright (C) 1999, 2000 Hugh Blemings & Pavel Janík ml.
11 Released under the terms of the GNU GPL, see file COPYING for more details.
13 Mgnokiidev gets passed a slave pty name by gnokiid and uses this
14 information to create a symlink from the pty to /dev/gnokii.
17 Revision 1.1.1.1 2001/11/25 21:59:23 short
18 :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
20 Revision 1.7 2001/09/14 12:38:00 pkot
23 Revision 1.6 2000/12/27 10:54:15 pkot
24 Added Unix98 PTYs support (Michael Mráka).
36 #include <sys/types.h>
45 int main(int argc, char *argv[])
48 char dev_name[DEVLEN];
50 /* Check we have one and only one command line argument. */
52 fprintf(stderr, "mgnokiidev takes one and only one argument!\n");
56 /* Check if argument has a reasonable length (less than MAXLEN characters) */
57 if (strlen(argv[1]) >= MAXLEN) {
58 fprintf(stderr, "Argument must be less than %d characters.\n", MAXLEN);
62 strncpy(dev_name, argv[1], DEVLEN);
64 /* Check for suspicious characters. */
65 aux = strlen(dev_name);
66 for (count = 0; count < aux; count ++)
67 if (!(isalnum(dev_name[count]) || dev_name[count]=='/')) {
68 fprintf(stderr, "Suspicious character at index %d in argument.\n", count);
75 /* Change group of slave pty to group of mgnokiidev */
76 err = chown(dev_name, -1, getgid());
79 perror("mgnokiidev - chown: ");
83 /* Change permissions to rw by group */
84 err = chmod(dev_name, S_IRGRP | S_IWGRP | S_IRUSR | S_IWUSR);
87 perror("mgnokiidev - chmod: ");
91 /* FIXME: Possible bug - should check that /dev/gnokii doesn't already exist
92 in case multiple users are trying to run gnokii. Well, but will be
93 mgnokiidev called then? I do not think so - you will probably got the
94 message serialport in use or similar. Don't you. I haven't tested it
97 /* Remove symlink in case it already exists. Don't care if it fails. */
98 unlink ("/dev/gnokii");
101 err = symlink(dev_name, "/dev/gnokii");
104 perror("mgnokiidev - symlink: ");