~ubuntu-branches/ubuntu/quantal/seyon/quantal

« back to all changes in this revision

Viewing changes to SePort.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve McIntyre
  • Date: 2001-12-19 17:24:13 UTC
  • Revision ID: james.westby@ubuntu.com-20011219172413-5l92k5tbflnjol7h
Tags: 2.20c-8
* Added Build-Depends on bison. Closes: #123699.
* Turned app-defaults files into conffiles after lintian warning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
#ifdef linux
52
52
#include <linux/serial.h>
53
53
#include <sys/ioctl.h>
54
 
#include <linux/fs.h>
 
54
/* #include <linux/fs.h> */
55
55
#include <linux/tty.h>
56
56
#endif
57
57
#endif
127
127
 
128
128
void
129
129
MdmPutString(s)
130
 
     char           *s;
 
130
    char           *s;
131
131
{
132
 
  char            c;
133
 
 
134
 
  usleep(MDELAY);
135
 
  for (; (c = *s); s++) {
136
 
    if (*s == '^' && *(s + 1))
137
 
      if (*(++s) == '^') c = *s;
138
 
      else c = *s & 0x1f;
139
 
 
140
 
    if (c == '~') sleep(1);
141
 
    else send_tbyte(c);
 
132
    char            c;
 
133
 
142
134
    usleep(MDELAY);
143
 
  }
 
135
    for (; (c = *s); s++) 
 
136
    {
 
137
        if (*s == '^' && *(s + 1))
 
138
        {
 
139
          if (*(++s) == '^') 
 
140
          {
 
141
              c = *s;
 
142
          }
 
143
          else 
 
144
          {
 
145
              c = *s & 0x1f;
 
146
          }
 
147
        }
 
148
        if (c == '~') 
 
149
          sleep(1);
 
150
        else 
 
151
          send_tbyte(c);
 
152
        usleep(MDELAY);
 
153
    }
144
154
}
145
155
 
146
156
void
150
160
                    *b,
151
161
                    *c;
152
162
{
153
 
  char            buf[REG_BUF];
154
 
 
155
 
  sprintf(buf, fmt, a, b, c);
156
 
  MdmPutString(buf);
 
163
    MdmPutString(FmtString(fmt,a,b,c));
157
164
}
158
165
 
159
166
void
224
231
         int             newModem;
225
232
{
226
233
  static Boolean  useModemControl = True;
227
 
  int             retStat;
 
234
  int             retStat = 0;
228
235
 
229
236
  if (newModem) useModemControl = True;
230
237
 
350
357
 
351
358
char           *
352
359
mport(s)                        /* get/set port string */
353
 
     char           *s;
 
360
    char           *s;
354
361
{
355
 
  if (s != NULL)
356
 
    strcpy(modem_port, s);
357
 
  return (modem_port);
 
362
    if (s != NULL)
 
363
        strncpy(modem_port, s, sizeof(modem_port));
 
364
    return (modem_port);
358
365
}
359
366
 
360
367
int
946
953
}
947
954
 
948
955
void
949
 
sendf_slowly(format, a, b, c)
950
 
     char           *format,
 
956
sendf_slowly(fmt, a, b, c)
 
957
     char           *fmt,
951
958
                    *a,
952
959
                    *b,
953
960
                    *c;
954
961
{
955
 
  char            buffer[SM_BUF];
956
 
 
957
 
  sprintf(buffer, format, a, b, c);
958
 
  send_slowly(buffer);
 
962
  send_slowly(FmtString(fmt,a,b,c));
959
963
}
960
964
 
961
965
void
989
993
LockModem(modem)
990
994
         String modem;
991
995
{
992
 
  strcpy(modem_port, modem);
 
996
  strncpy(modem_port, modem, REG_BUF);
993
997
  return lock_tty();
994
998
}
995
999
 
1004
1008
int
1005
1009
lock_tty()
1006
1010
{
1007
 
  int             lfd;
1008
 
  pid_t           pid,
1009
 
                  lckpid;
1010
 
  char           *modemname;
 
1011
    int             lfd;
 
1012
    pid_t           pid,
 
1013
        lckpid;
 
1014
    char           *modemname;
1011
1015
#if LF_USE_ASCII_PID
1012
 
  char            pidstr[20],
1013
 
                  lckpidstr[20];
1014
 
  int             nb;
 
1016
    char            pidstr[20],
 
1017
        lckpidstr[20];
 
1018
    int             nb;
1015
1019
#endif
1016
1020
#if LF_USE_DEV_NUMBERS
1017
 
  struct stat  mbuf;
 
1021
    struct stat  mbuf;
1018
1022
#endif
1019
1023
 
1020
 
  /* Get our PID, and initialize the filename strings */
1021
 
  pid = getpid();
 
1024
    /* Get our PID, and initialize the filename strings */
 
1025
    pid = getpid();
1022
1026
 
1023
1027
#if !LF_USE_DEV_NUMBERS
1024
 
  modemname = strrchr(modem_port, '/');
1025
 
  sprintf(lckf, "%s/%s%s", LF_PATH, LF_PREFIX, 
1026
 
                  (modemname ? (modemname + 1) : modem_port));
 
1028
    modemname = strrchr(modem_port, '/');
 
1029
    if(modemname)
 
1030
    {
 
1031
        if( SM_BUF > (1 + strlen(LF_PATH) + strlen(LF_PREFIX) + strlen(modemname)))
 
1032
          sprintf(lckf, "%s/%s%s", LF_PATH, LF_PREFIX, (modemname + 1));
 
1033
        else
 
1034
        {
 
1035
          SePErrorF("Buffer too small for lock filename in lock_tty(): %s", modemname, "", "");
 
1036
          return -1;
 
1037
        }
 
1038
    }
 
1039
    else
 
1040
    {
 
1041
        if( SM_BUF > (1 + strlen(LF_PATH) + strlen(LF_PREFIX) + strlen(modem_port)))
 
1042
          sprintf(lckf, "%s/%s%s", LF_PATH, LF_PREFIX, (modem_port));
 
1043
        else
 
1044
        {
 
1045
          SePErrorF("Buffer too small for lock filename in lock_tty(): %s", modem_port, "", "");
 
1046
          return -1;
 
1047
        }
 
1048
    }
 
1049
 
1027
1050
#else
1028
 
  if(stat(modem_port, &mbuf) < 0) {
1029
 
        SePErrorF("could not stat modem port %s", modem_port, "", "");
1030
 
        return -1;
1031
 
  }
1032
 
  sprintf(lckf,"%s/%s%03u.%03u.%03u", LF_PATH, LF_PREFIX, major(mbuf.st_dev),
1033
 
                  major(mbuf.st_rdev), minor(mbuf.st_rdev));
 
1051
    if(stat(modem_port, &mbuf) < 0) {
 
1052
        SePErrorF("could not stat modem port %s", modem_port, "", "");
 
1053
        return -1;
 
1054
    }
 
1055
    if( SM_BUF > (10 + strlen(LF_PATH) + strlen(LF_PREFIX)))
 
1056
        sprintf(lckf,"%s/%s%03u.%03u.%03u", LF_PATH, LF_PREFIX, major(mbuf.st_dev),
 
1057
              major(mbuf.st_rdev), minor(mbuf.st_rdev));
 
1058
    else
 
1059
    {
 
1060
        SePErrorF("Buffer too small for lock filename in lock_tty():", "", "", "");
 
1061
        return -1;
 
1062
    }
1034
1063
#endif /* LF_USE_DEV_NUMBERS */
1035
1064
 
1036
 
  sprintf(ltmp, "%s/%s%d", LF_PATH, "LTMP.", pid);
1037
 
  /* Create the LTMP.<pid> file and scribble our PID in it */
1038
 
  unlink(ltmp);
1039
 
  if ((lfd = creat(ltmp, 0644)) == -1) {
1040
 
    SePErrorF("Could not create temporary lock file %s", ltmp, "", "");
1041
 
    return -1;
1042
 
  }
 
1065
    if( SM_BUF > (11 + strlen(LF_PATH)))
 
1066
        sprintf(ltmp, "%s/%s%d", LF_PATH, "LTMP.", pid);
 
1067
    else
 
1068
    {
 
1069
        SePErrorF("Buffer too small for ltmp filename in lock_tty():", "", "", "");
 
1070
        return -1;
 
1071
    }
 
1072
    /* Create the LTMP.<pid> file and scribble our PID in it */
 
1073
    unlink(ltmp);
 
1074
    if ((lfd = creat(ltmp, 0644)) == -1) {
 
1075
        SePErrorF("Could not create temporary lock file %s", ltmp, "", "");
 
1076
        return -1;
 
1077
    }
1043
1078
 
1044
1079
#if LF_USE_ASCII_PID
1045
 
  sprintf(pidstr, "%10d\n", pid);
1046
 
  write(lfd, pidstr, 11);
 
1080
    /* pidstr is easily large enough */
 
1081
    sprintf(pidstr, "%10d\n", pid);
 
1082
    write(lfd, pidstr, 11);
1047
1083
#else
1048
 
  write(lfd, (char*)&pid, sizeof(pid));
 
1084
    write(lfd, (char*)&pid, sizeof(pid));
1049
1085
#endif
1050
 
  close(lfd);
 
1086
    close(lfd);
1051
1087
 
1052
1088
  /*
1053
1089
   * Attempt to link directly - if it works, we're done.