int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Usage: %s tty_line\n" "where tty_line is the TTY on which to set the Lunix line discipline.\n\n", argv[0]); exit(1); } if (tty_open(argv[1]) < 0) return 1; fprintf(stderr, "Line discipline set on %s, press ^C to release the TTY...\n", argv[1]); (void) signal(SIGHUP, sig_catch); (void) signal(SIGINT, sig_catch); (void) signal(SIGQUIT, sig_catch); (void) signal(SIGTERM, sig_catch); while (pause()) ; /* Unreachable */ return 100; }
int main(int argc, char *argv[]) { char rxChar; char txChar; printf("Acme Serial Test (press ctrl-c to exit)\n"); if (tty_open(argv[1])<0) { fprintf (stderr,"tty open error %s\n", strerror(errno)); exit(EXIT_FAILURE); } if (stdin_init()<0) { printf("stdin init error %s\n", strerror(errno)); exit(EXIT_FAILURE); } if (signal (SIGINT, termination_handler) == SIG_IGN) signal (SIGINT, SIG_IGN); if (signal (SIGHUP, termination_handler) == SIG_IGN) signal (SIGHUP, SIG_IGN); if (signal (SIGTERM, termination_handler) == SIG_IGN) signal (SIGTERM, SIG_IGN); while (1) { if (read (STDIN_FILENO, &txChar, 1)>0) { tty_printf("TX: 0x%02X",txChar); if (txChar>=32 && txChar<=126) tty_printf(" [%c]",txChar); tty_printf("\n"); } if (read(tty_fd,&rxChar,1)>0) { printf("RX = 0x%02X",rxChar); if (rxChar>=32 && rxChar<=126) printf(" [%c]",rxChar); printf("\n"); } } return EXIT_SUCCESS; }
int bmc_send_command(char *cmd) { int i, ret = 0; for (i = 1; i <= TTY_RETRY; i++) { if (tty_open() != 0) { printf("ERROR: Cannot open TTY device\n"); continue; } if (tty_login() != 0) { //printf("ERROR: Cannot login TTY device\n"); tty_close(); continue; } snprintf(tty_buf, MAXIMUM_TTY_BUFFER_LENGTH, "%s", cmd); ret = tty_exec_buf(TTY_I2C_TIMEOUT * i, TTY_PROMPT); tty_close(); if (ret != 0) { printf("ERROR: bmc_send_command timed out\n"); continue; } return 0; } AIM_LOG_ERROR("Unable to send command to bmc(%s)\r\n", cmd); return -1; }
void need_scr() { scr_handle = tty_open(); tty_set_attribute(scr_handle,0x02,0x00); tty_clear_display(scr_handle); set_focus(0,scr_handle,1); seed(); }
/* * Opens the input data-feed. Given a feedname (path in the file system), * determine what type of input feed it is. Attempt to open * the feed. Hook up the appropriate read_, _stats, and (optional) _close * function pointers. Return errno on failure else set *fdp to the descriptor * and return 0. * * @param feedfname [in] The name of the input data-feed * @param fdp [out] The file-descriptor of the input data-feed * @param maxProdSize [in] The size, in bytes, of the largest expected * data-product * Returns (if INPUT_IS_SOCKET): * ENOENT gethostbyname() failure. * EAFNOSUPPORT AF_INET address-family not supported. * EMFILE No more file descriptors available for this process. * ENFILE No more file descriptors available for the system. * EACCES The process does not have appropriate privileges. * ENOBUFS Insufficient resources were available in the system to * perform the operation. * ENOMEM Insufficient memory was available to fulfill the request. * ENOSR There were insufficient STREAMS resources available for the * operation to complete. * EADDRNOTAVAIL The specified address is not available from the local * machine. * ECONNREFUSED The target address was not listening for connections or * refused the connection request. * EINTR The attempt to establish a connection was interrupted by * delivery of a signal that was caught; the connection will be * established asynchronously. * ENETUNREACH No route to the network is present. * EPROTOTYPE The specified address has a different type than the socket * bound to the specified peer address. * ETIMEDOUT The attempt to connect timed out before a connection was * made. * ECONNRESET Remote host reset the connection request. * EHOSTUNREACH The destination host cannot be reached (probably because the * host is down or a remote router cannot reach it). * ENETDOWN The local interface used to reach the destination is down. */ int open_feed(const char *feedfname, int *const fdp, const unsigned long maxProdSize) { extern char *rawfname; /* declared in main() module */ int status = ENOERR; #if NET if(INPUT_IS_SOCKET) { status = port_open(feedfname, (unsigned short) server_port, fdp); if(status != ENOERR) return status; if((status = initTheXbuf(read_file, maxProdSize)) != ENOERR) return status; feed_stats = file_stats; feed_close = file_close; } else /* dangling else */ #endif /* NET */ switch( which(feedfname) ) { #ifdef TTY case TTY : if((status = tty_open(feedfname, fdp)) != ENOERR) return status; if((status = initTheXbuf(read_tty, maxProdSize)) != ENOERR) return status; feed_stats = tty_stats; feed_close = tty_close; break; #endif /* TTY */ default : /* just treat it like a file */ if(*feedfname == '-' && feedfname[1] == 0) { /* use stdin */ *fdp = fileno(stdin); unotice("FILE stdin"); } else { if((status = file_open(feedfname, fdp)) != ENOERR) return status; } if((status = initTheXbuf(read_file, maxProdSize)) != ENOERR) return status; feed_stats = file_stats; feed_close = file_close; break; } if(rawfname != NULL) { (void) open_rawfile( rawfname ); } return status; }
int trstty_open(uint8_t minor, uint16_t flags) { /* Serial port cards are optional */ if (minor < 8 && !(ports & (1 << minor))) { udata.u_error = ENODEV; return -1; } return tty_open(minor, flags); }
// Pic void init_serial_comm(){ pthread_mutex_init(&m_analizza_pacchetto, NULL); //Variabile contatore int i; //open_port(c, 0, 1, 0); tty_open(PIC_DEVICE); //tty_open_rfid(); //apri_seriale(); for(i=0;i<N_PIC_MES_BUFF;i++){*(pic_message_buffer+i)=malloc(MAX_PIC_MES_LENGHT*sizeof(unsigned char));} current_pic_packet_slot=0; }
int tty_openport(char *port) { char str[20]="/dev/",*p; int speed=0; if(*port!='/')xstrcat(str,port,sizeof(str)); else xstrcpy(str,port,sizeof(str)); if((p=strchr(str,':'))) { *p++=0; speed=atoi(p); } if(!speed)speed=DEFAULT_SPEED; return tty_open(str,speed); }
int modbus_open(struct config *cfg, const char *dev, int baud, int byte_interval, int byte_interval_limit) { cfg->baud = baud; cfg->byte_interval = byte_interval; cfg->byte_interval_limit = byte_interval_limit; cfg->fd = tty_open(dev); if (cfg->fd < 0) return -1; uint8_t buf[1]; while (read(cfg->fd, buf, 1) > 0) ; return 0; }
static status_t master_open(const char *name, uint32 flags, void **_cookie) { bool findUnusedTTY = strcmp(name, "ptmx") == 0; int32 index = -1; if (!findUnusedTTY) { index = get_tty_index(name); if (index >= (int32)kNumTTYs) return B_ERROR; } TRACE(("master_open: TTY index = %ld (name = %s)\n", index, name)); MutexLocker globalLocker(gGlobalTTYLock); if (findUnusedTTY) { for (index = 0; index < (int32)kNumTTYs; index++) { if (gMasterTTYs[index].ref_count == 0) break; } if (index >= (int32)kNumTTYs) return ENOENT; } else if (gMasterTTYs[index].ref_count > 0) { // we're already open! return B_BUSY; } status_t status = tty_open(&gMasterTTYs[index], &master_service); if (status < B_OK) { // initializing TTY failed return status; } master_cookie *cookie; status = create_master_cookie(cookie, &gMasterTTYs[index], &gSlaveTTYs[index], flags); if (status != B_OK) { tty_close(&gMasterTTYs[index]); return status; } add_tty_cookie(cookie); *_cookie = cookie; return B_OK; }
int rctty_open(uint_fast8_t minor, uint16_t flag) { if (acia_present && minor != 1) { udata.u_error = ENODEV; return -1; } if ((minor == 1 || minor == 2) && !sio_present) { udata.u_error = ENODEV; return -1; } if ((minor == 3 || minor == 4) && !sio1_present) { udata.u_error = ENODEV; return -1; } return tty_open(minor, flag); }
static void connect_event_cb(GIOChannel *chan, GError *conn_err, gpointer data) { struct serial_proxy *prx = data; int sk; if (conn_err) { error("%s", conn_err->message); goto drop; } /* Connect local */ switch (prx->type) { case UNIX_SOCKET_PROXY: sk = unix_socket_connect(prx->address); break; case TTY_PROXY: sk = tty_open(prx->address, &prx->proxy_ti); break; case TCP_SOCKET_PROXY: sk = tcp_socket_connect(prx->address); break; default: sk = -1; } if (sk < 0) goto drop; prx->local = g_io_channel_unix_new(sk); g_io_add_watch(prx->rfcomm, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, forward_data, prx); g_io_add_watch(prx->local, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL, forward_data, prx); return; drop: g_io_channel_shutdown(prx->rfcomm, TRUE, NULL); g_io_channel_unref(prx->rfcomm); prx->rfcomm = NULL; }
void tty_serial_init() { tty_fds = tty_open(MODEM_DEVICE); tty_serial_config(tty_fds); waspmote_seq = 0; if((inbuf = malloc(MAX_FRAME_SIZE)) == NULL ) { printf("%s\n","fail to allocate memory for inbuf..."); exit(EXIT_FAILURE); } else { memset(inbuf,0,MAX_FRAME_SIZE); } if((outbuf = malloc(MAX_FRAME_SIZE)) == NULL ) { printf("%s\n","fail to allocate memory for outbuf..."); exit(EXIT_FAILURE); } else { memset(outbuf,0,MAX_FRAME_SIZE); } }
/* * \brief Open a serial port. The serial port is registered for further operations. * * \param id the instance id * \param portname the serial port to open, e.g. /dev/ttyUSB0, /dev/ttyACM0, /dev/spidev1.1 * * \return 0 in case of a success, -1 in case of an error */ int serial_open(int id, char* portname) { int ret = 0; if(strstr(portname, "tty")) { serials[id].fd = tty_open(portname); } else if(strstr(portname, "spi")) { serials[id].fd = spi_open(portname); } if(serials[id].fd < 0) { ret = -1; } return ret; }
/* * icom_init() - open and initialize serial interface * * This routine opens the serial interface for raw transmission; that * is, character-at-a-time, no stripping, checking or monkeying with the * bits. For Unix, an input operation ends either with the receipt of a * character or a 0.5-s timeout. */ int icom_init( const char *device, /* device name/link */ int speed, /* line speed */ int trace /* trace flags */ ) { TTY ttyb; int fd; int rc; int saved_errno; UNUSED_ARG(trace); fd = tty_open(device, O_RDWR, 0777); if (fd < 0) return -1; rc = tcgetattr(fd, &ttyb); if (rc < 0) { saved_errno = errno; close(fd); errno = saved_errno; return -1; } ttyb.c_iflag = 0; /* input modes */ ttyb.c_oflag = 0; /* output modes */ ttyb.c_cflag = IBAUD|CS8|CLOCAL; /* control modes (no read) */ ttyb.c_lflag = 0; /* local modes */ ttyb.c_cc[VMIN] = 0; /* min chars */ ttyb.c_cc[VTIME] = 5; /* receive timeout */ cfsetispeed(&ttyb, (u_int)speed); cfsetospeed(&ttyb, (u_int)speed); rc = tcsetattr(fd, TCSANOW, &ttyb); if (rc < 0) { saved_errno = errno; close(fd); errno = saved_errno; return -1; } return (fd); }
int nc100_tty_open(uint8_t minor, uint16_t flag) { int err; if (!minor) minor = udata.u_ptab->p_tty; err = tty_open(minor, flag); if (err) return err; if (minor == 2) { mod_control(0, 0x10); /* turn on the line driver */ nap(); mod_control(0x06, 0x01); /* 9600 baud */ #ifdef CONFIG_NC200 irqen = 0x1C; #else irqen = 0x0B; /* Allow serial interrupts */ #endif } return (0); }
/* * atom_start - initialize data for processing */ static bool atom_start( int unit, /* unit number (not used) */ struct peer *peer /* peer structure pointer */ ) { struct refclockproc *pp; struct ppsunit *up; char device[80]; /* * Allocate and initialize unit structure */ pp = peer->procptr; peer->precision = PRECISION; pp->clockdesc = DESCRIPTION; pp->stratum = STRATUM_UNSPEC; memcpy((char *)&pp->refid, REFID, REFIDLEN); peer->sstclktype = CTL_SST_TS_ATOM; up = emalloc(sizeof(struct ppsunit)); memset(up, 0, sizeof(struct ppsunit)); pp->unitptr = up; /* * Open PPS device. This can be any serial or parallel port and * not necessarily the port used for the associated radio. */ snprintf(device, sizeof(device), DEVICE, unit); up->fddev = tty_open(device, O_RDWR, 0777); if (up->fddev <= 0) { msyslog(LOG_ERR, "refclock_atom: %s: %m", device); return false; } /* * Light up the PPSAPI interface. */ return (refclock_ppsapi(up->fddev, &up->atom)); }
pid_t pty_fork(int* ptrfdm, char* slave_name, struct termios* slave_termios, struct winsize* slave_winsize) { int fdm, fds; pid_t pid; char pts_name[20]; if ((fdm = pty_open(pts_name)) < 0) die("can't open pty %s\n", pts_name); if (slave_name) strcpy(slave_name, pts_name); if ((pid = fork()) < 0) die("fork error\n"); if (!pid) { if (setsid() < 0) die("setsid error"); if ((fds = tty_open(fdm, pts_name)) < 0) die("can't open slave pty %s\n", pts_name); close(fdm); if (slave_termios) if (tcsetattr(fds, TCSANOW, slave_termios) < 0) die("tcsetattr error on slave pty"); if (slave_winsize) if (ioctl(fds, TIOCSWINSZ, slave_winsize) < 0) die("TIOCSWINSZ error on slave pty"); if (dup2(fds, STDIN_FILENO) != STDIN_FILENO) die("dup2 error to stdin"); if (dup2(fds, STDOUT_FILENO) != STDOUT_FILENO) die("dup2 error to stdout"); if (dup2(fds, STDERR_FILENO) != STDERR_FILENO) die("dup2 error to stderr"); if (fds > STDERR_FILENO) close(fds); return 0; } *ptrfdm = fdm; return pid; }
int cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) { struct cmd_target_data *data = self->data; struct session *s; char *cause; if (ctx->curclient != NULL) return (0); if (ARRAY_LENGTH(&sessions) == 0) { ctx->error(ctx, "no sessions"); return (-1); } if ((s = cmd_find_session(ctx, data->target)) == NULL) return (-1); if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) { ctx->error(ctx, "not a terminal"); return (-1); } if (tty_open(&ctx->cmdclient->tty, &cause) != 0) { ctx->error(ctx, "terminal open failed: %s", cause); xfree(cause); return (-1); } if (data->flags & CMD_DFLAG) server_write_session(s, MSG_DETACH, NULL, 0); ctx->cmdclient->session = s; server_write_client(ctx->cmdclient, MSG_READY, NULL, 0); recalculate_sizes(); server_redraw_client(ctx->cmdclient); return (1); }
static void tty_echo(int echo) { struct termios tio; int fd; if ((fd = tty_open()) < 0) return; if (tcgetattr(fd, &tio) < 0) { msg_err("tcgetattr"); return; } if (echo == TTY_ECHO_ON) { tio.c_lflag |= ECHO; tio.c_lflag |= ICANON; } else if (echo == TTY_ECHO_OFF) { tio.c_lflag &= ~ECHO; tio.c_lflag &= ~ICANON; } if (tcsetattr(fd, TCSANOW, &tio) < 0) msg_err("tcsetattr"); }
int main() { tty_open(MODEMDEVICE); tty_serial_config(tty_fds); /* char test char a[2] = "01"; char b[2] = {0,1}; printf("%c %c %d %d\n",a[1],b[1],a[1],b[1]); */ char c[2] = "c"; char outbuf[] = {0x7E,0x00,0x04,0x08,0x01,0x4E,0x49,0x5F}; char* inbuf; //int sl = strlen(outbuf); //==>1 0x00 will end counting //int len = write(STDOUT_FILENO,outbuf,8); //printf("%d\n",len); while(c[0]!='q') { read(STDIN_FILENO,c,2); if(c[0]=='w') { int l = write(tty_fds,outbuf,8); printf("%c %d %d\n",c[1],c[1],l); } } return 0; }
int cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct session *s, *old_s, *groupwith; struct window *w; struct window_pane *wp; struct environ env; struct termios tio, *tiop; struct passwd *pw; const char *newname, *target, *update, *cwd; char *overrides, *cmd, *cause; int detached, idx; u_int sx, sy, i; newname = args_get(args, 's'); if (newname != NULL && session_find(newname) != NULL) { ctx->error(ctx, "duplicate session: %s", newname); return (-1); } target = args_get(args, 't'); if (target != NULL) { groupwith = cmd_find_session(ctx, target); if (groupwith == NULL) return (-1); } else groupwith = NULL; /* * There are three cases: * * 1. If cmdclient is non-NULL, new-session has been called from the * command-line - cmdclient is to become a new attached, interactive * client. Unless -d is given, the terminal must be opened and then * the client sent MSG_READY. * * 2. If cmdclient is NULL, new-session has been called from an * existing client (such as a key binding). * * 3. Both are NULL, the command was in the configuration file. Treat * this as if -d was given even if it was not. * * In all cases, a new additional session needs to be created and * (unless -d) set as the current session for the client. */ /* Set -d if no client. */ detached = args_has(args, 'd'); if (ctx->cmdclient == NULL && ctx->curclient == NULL) detached = 1; /* * Save the termios settings, part of which is used for new windows in * this session. * * This is read again with tcgetattr() rather than using tty.tio as if * detached, tty_open won't be called. Because of this, it must be done * before opening the terminal as that calls tcsetattr() to prepare for * tmux taking over. */ if (ctx->cmdclient != NULL && ctx->cmdclient->tty.fd != -1) { if (tcgetattr(ctx->cmdclient->tty.fd, &tio) != 0) fatal("tcgetattr failed"); tiop = &tio; } else tiop = NULL; /* Open the terminal if necessary. */ if (!detached && ctx->cmdclient != NULL) { if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) { ctx->error(ctx, "not a terminal"); return (-1); } overrides = options_get_string(&global_s_options, "terminal-overrides"); if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) { ctx->error(ctx, "open terminal failed: %s", cause); xfree(cause); return (-1); } } /* Get the new session working directory. */ if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL) cwd = ctx->cmdclient->cwd; else { pw = getpwuid(getuid()); if (pw->pw_dir != NULL && *pw->pw_dir != '\0') cwd = pw->pw_dir; else cwd = "/"; } /* Find new session size. */ if (detached) { sx = 80; sy = 24; } else if (ctx->cmdclient != NULL) { sx = ctx->cmdclient->tty.sx; sy = ctx->cmdclient->tty.sy; } else { sx = ctx->curclient->tty.sx; sy = ctx->curclient->tty.sy; } if (sy > 0 && options_get_number(&global_s_options, "status")) sy--; if (sx == 0) sx = 1; if (sy == 0) sy = 1; /* Figure out the command for the new window. */ if (target != NULL) cmd = NULL; else if (args->argc != 0) cmd = args->argv[0]; else cmd = options_get_string(&global_s_options, "default-command"); /* Construct the environment. */ environ_init(&env); update = options_get_string(&global_s_options, "update-environment"); if (ctx->cmdclient != NULL) environ_update(update, &ctx->cmdclient->environ, &env); /* Create the new session. */ idx = -1 - options_get_number(&global_s_options, "base-index"); s = session_create(newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause); if (s == NULL) { ctx->error(ctx, "create session failed: %s", cause); xfree(cause); return (-1); } environ_free(&env); /* Set the initial window name if one given. */ if (cmd != NULL && args_has(args, 'n')) { w = s->curw->window; xfree(w->name); w->name = xstrdup(args_get(args, 'n')); options_set_number(&w->options, "automatic-rename", 0); } /* * If a target session is given, this is to be part of a session group, * so add it to the group and synchronize. */ if (groupwith != NULL) { session_group_add(groupwith, s); session_group_synchronize_to(s); session_select(s, RB_ROOT(&s->windows)->idx); } /* * Set the client to the new session. If a command client exists, it is * taking this session and needs to get MSG_READY and stay around. */ if (!detached) { if (ctx->cmdclient != NULL) { server_write_client(ctx->cmdclient, MSG_READY, NULL, 0); old_s = ctx->cmdclient->session; if (old_s != NULL) ctx->cmdclient->last_session = old_s; ctx->cmdclient->session = s; session_update_activity(s); server_redraw_client(ctx->cmdclient); } else { old_s = ctx->curclient->session; if (old_s != NULL) ctx->curclient->last_session = old_s; ctx->curclient->session = s; session_update_activity(s); server_redraw_client(ctx->curclient); } } recalculate_sizes(); server_update_socket(); /* * If there are still configuration file errors to display, put the new * session's current window into more mode and display them now. */ if (cfg_finished && !ARRAY_EMPTY(&cfg_causes)) { wp = s->curw->window->active; window_pane_set_mode(wp, &window_copy_mode); window_copy_init_for_output(wp); for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) { cause = ARRAY_ITEM(&cfg_causes, i); window_copy_add(wp, "%s", cause); xfree(cause); } ARRAY_FREE(&cfg_causes); } return (!detached); /* 1 means don't tell command client to exit */ }
int main(int argc, char *argv[]) { char path_buf[128] = ""; char *path_dev; char buff[128]; const char *speed = NULL; const char *proto = DEF_PROTO; const char *extcmd = NULL; int s; static struct option longopts[] = { { "version", 0, NULL, 'V' }, { NULL, 0, NULL, 0 } }; path_dev = path_buf; /* Scan command line for any arguments. */ opterr = 0; while ((s = getopt_long(argc, argv, "c:ehlLmnp:qs:vdVk:o:", longopts, NULL)) != EOF) switch(s) { case 'c': extcmd = optarg; break; case 'e': opt_e = 1 - opt_e; break; case 'h': opt_h = 1 - opt_h; break; #ifdef SIOCSKEEPALIVE case 'k': opt_k = atoi(optarg); break; #endif case 'L': opt_L = 1 - opt_L; break; case 'l': opt_l = 1 - opt_l; break; case 'm': opt_m = 1 - opt_m; break; case 'n': opt_n = 1 - opt_n; break; #ifdef SIOCSOUTFILL case 'o': opt_o = atoi(optarg); break; #endif case 'p': proto = optarg; break; case 'q': opt_q = 1 - opt_q; break; case 's': speed = optarg; break; case 'd': opt_d = 1 - opt_d; break; case 'v': opt_v = 1 - opt_v; break; case 'V': version(); /*NOTREACHED*/ default: usage(); /*NOTREACHED*/ } if (setvbuf(stdout,0,_IOLBF,0)) { if (opt_q == 0) fprintf(stderr, _("slattach: setvbuf(stdout,0,_IOLBF,0) : %s\n"), strerror(errno)); exit(1); } activate_init(); if (!strcmp(proto, "tty")) opt_m++; /* Is a terminal given? */ if (optind != (argc - 1)) usage(); safe_strncpy(path_buf, argv[optind], sizeof(path_buf)); if (!strcmp(path_buf, "-")) { opt_e = 1; path_dev = NULL; if (tty_open(NULL, speed) < 0) { return(3); } } else { path_dev = path_buf; if (tty_open(path_dev, speed) < 0) { return(3); } } /* Start the correct protocol. */ if (!strcmp(proto, "tty")) { tty_sdisc = N_TTY; tty_close(); return(0); } if (activate_ld(proto, tty_fd)) return(1); if ((opt_v == 1) || (opt_d == 1)) { if (tty_get_name(buff)) { return(3); } printf(_("%s started"), proto); if (path_dev != NULL) printf(_(" on %s"), path_dev); if (path_pts != NULL) printf(_(" ptsname %s"), path_pts); printf(_(" interface %s\n"), buff); } /* Configure keepalive and outfill. */ #ifdef SIOCSKEEPALIVE if (opt_k && (ioctl(tty_fd, SIOCSKEEPALIVE, &opt_k) < 0)) fprintf(stderr, "slattach: ioctl(SIOCSKEEPALIVE): %s\n", strerror(errno)); #endif #ifdef SIOCSOUTFILL if (opt_o && (ioctl(tty_fd, SIOCSOUTFILL, &opt_o) < 0)) fprintf(stderr, "slattach: ioctl(SIOCSOUTFILL): %s\n", strerror(errno)); #endif (void) signal(SIGHUP, sig_catch); (void) signal(SIGINT, sig_catch); (void) signal(SIGQUIT, sig_catch); (void) signal(SIGTERM, sig_catch); /* Wait until we get killed if hanging on a terminal. */ if (opt_e == 0) { while(1) { if(opt_h == 1) { /* hangup on carrier loss */ int n = 0; ioctl(tty_fd, TIOCMGET, &n); if(!(n & TIOCM_CAR)) break; sleep(15); } else sleep(60); }; tty_close(); if(extcmd) /* external command on exit */ exit(system(extcmd)); } exit(0); }
/* * arc_start - open the devices and initialize data for processing */ static int arc_start( int unit, struct peer *peer ) { register struct arcunit *up; struct refclockproc *pp; int fd; char device[20]; #ifdef HAVE_TERMIOS struct termios arg; #endif msyslog(LOG_NOTICE, "ARCRON: %s: opening unit %d", arc_version, unit); #ifdef DEBUG if(debug) { printf("arc: %s: attempt to open unit %d.\n", arc_version, unit); } #endif /* Prevent a ridiculous device number causing overflow of device[]. */ if((unit < 0) || (unit > 255)) { return(0); } /* * Open serial port. Use CLK line discipline, if available. */ snprintf(device, sizeof(device), DEVICE, unit); if (!(fd = refclock_open(device, SPEED, LDISC_CLK))) return(0); #ifdef DEBUG if(debug) { printf("arc: unit %d using open().\n", unit); } #endif fd = tty_open(device, OPEN_FLAGS, 0777); if(fd < 0) { #ifdef DEBUG if(debug) { printf("arc: failed [tty_open()] to open %s.\n", device); } #endif return(0); } #ifndef SYS_WINNT fcntl(fd, F_SETFL, 0); /* clear the descriptor flags */ #endif #ifdef DEBUG if(debug) { printf("arc: opened RS232 port with file descriptor %d.\n", fd); } #endif #ifdef HAVE_TERMIOS tcgetattr(fd, &arg); arg.c_iflag = IGNBRK | ISTRIP; arg.c_oflag = 0; arg.c_cflag = B300 | CS8 | CREAD | CLOCAL | CSTOPB; arg.c_lflag = 0; arg.c_cc[VMIN] = 1; arg.c_cc[VTIME] = 0; tcsetattr(fd, TCSANOW, &arg); #else msyslog(LOG_ERR, "ARCRON: termios not supported in this driver"); (void)close(fd); return 0; #endif up = emalloc(sizeof(*up)); /* Set structure to all zeros... */ memset(up, 0, sizeof(*up)); pp = peer->procptr; pp->io.clock_recv = arc_receive; pp->io.srcclock = (caddr_t)peer; pp->io.datalen = 0; pp->io.fd = fd; if (!io_addclock(&pp->io)) { close(fd); pp->io.fd = -1; free(up); return(0); } pp->unitptr = (caddr_t)up; /* * Initialize miscellaneous variables */ peer->precision = PRECISION; peer->stratum = 2; /* Default to stratum 2 not 0. */ pp->clockdesc = DESCRIPTION; if (peer->MODE > 3) { msyslog(LOG_NOTICE, "ARCRON: Invalid mode %d", peer->MODE); return 0; } #ifdef DEBUG if(debug) { printf("arc: mode = %d.\n", peer->MODE); } #endif switch (peer->MODE) { case 1: memcpy((char *)&pp->refid, REFID_MSF, 4); break; case 2: memcpy((char *)&pp->refid, REFID_DCF77, 4); break; case 3: memcpy((char *)&pp->refid, REFID_WWVB, 4); break; default: memcpy((char *)&pp->refid, REFID, 4); break; } /* Spread out resyncs so that they should remain separated. */ up->next_resync = current_time + INITIAL_RESYNC_DELAY + (67*unit)%1009; #if 0 /* Not needed because of zeroing of arcunit structure... */ up->resyncing = 0; /* Not resyncing yet. */ up->saved_flags = 0; /* Default is all flags off. */ /* Clear send buffer out... */ { int i; for(i = CMDQUEUELEN; i >= 0; --i) { up->cmdqueue[i] = '\0'; } } #endif #ifdef ARCRON_KEEN up->quality = QUALITY_UNKNOWN; /* Trust the clock immediately. */ #else up->quality = MIN_CLOCK_QUALITY;/* Don't trust the clock yet. */ #endif peer->action = arc_event_handler; ENQUEUE(up); return(1); }
void handle_loopback (struct deviceinfo *unit, struct digi_node *node, struct digi_chan *chan, int port) { char full_line[81]; int i = 0, option = EOF; struct termios sv_tios; char test_data[TBUFSIZ + 1]; char read_data[TBUFSIZ + 1]; char string[200], ttyname[200]; int r = 3; int rwfd; WINDOW *lbwin = GetWin(LBWin); #define TITLE_LINE 1 #define DESC_LINE 2 #define DESC2_LINE 3 #define SEP_LINE 4 #define FIRST_DATA 5 #define SEP2_LINE 15 #define RESULT_LINE 16 show_panel (GetPan(LBWin)); update_panels (); doupdate (); next_result = 0; test_cases = 0; test_passes = 0; if (DPAGetPortName(unit, node, chan, port, ttyname) == NULL) { ttyname[0] ='\0'; } while (option == EOF) { erase_win (LBWin); wattrset (lbwin, make_attr (A_BOLD, WHITE, BLUE)); mvwprintw (lbwin, TITLE_LINE, 1, "%-*.*s", 76, 76, " "); mvwprintw (lbwin, RESULT_LINE, 1, "%-*.*s", 76, 76, " "); mvwprintw (lbwin, TITLE_LINE, 32, " Loop Back Test "); sprintf (full_line, "Tests Executed: %-12d Passed: %-12d Failed: %d", test_cases, test_passes, test_cases - test_passes); mvwprintw (lbwin, RESULT_LINE, center(LBWin, strlen(full_line)), full_line); sprintf (clbuf, "Unit IP Address: %s Port #: %d Name: %s", unit->host, port + 1, ttyname); i = strlen (clbuf); mvwprintw (GetWin(LBWin), DESC_LINE, 1, "%*s", GetWidth(LBWin) - 2, " "); mvwprintw (GetWin(LBWin), DESC2_LINE, 1, "%*s", GetWidth(LBWin) - 2, " "); mvwprintw (lbwin, DESC2_LINE, 2, clbuf); mvwprintw (lbwin, DESC_LINE, 2, "Device Description: %-*.*s", GetWidth(LBWin) - 2 - 2 - 2 - 20, GetWidth(LBWin) - 2 - 2 - 2 - 20, node->nd_ps_desc); if (!vanilla) wattrset (lbwin, make_attr (A_ALTCHARSET, CYAN, BLACK)); else wattrset (lbwin, make_attr (A_NORMAL, CYAN, BLACK)); wmove (lbwin, SEP_LINE, 1); for (i = 0; i < 77; i++) waddch (lbwin, mapchar(ACS_HLINE)); mvwaddch (lbwin, SEP_LINE, 0, mapchar(ACS_LTEE)); mvwaddch (lbwin, SEP_LINE, 77, mapchar(ACS_RTEE)); wmove (lbwin, SEP2_LINE, 1); for (i = 0; i < 77; i++) waddch (lbwin, mapchar(ACS_HLINE)); mvwaddch (lbwin, SEP2_LINE, 0, mapchar(ACS_LTEE)); mvwaddch (lbwin, SEP2_LINE, 77, mapchar(ACS_RTEE)); wattrset (lbwin, make_attr (A_NORMAL, WHITE, BLACK)); wrefresh (lbwin); wattrset (GetWin(MainWin), make_attr (A_NORMAL, WHITE, BLUE)); commandline (clbuf, "Press ANY key to Halt the test", NULL); mvwprintw (GetWin(MainWin), KEY_LINE, 0, clbuf); wattroff (GetWin(MainWin), make_attr (A_NORMAL, WHITE, BLUE)); wrefresh (GetWin(MainWin)); change_term (0, 10); option = EOF; r = 5; if (chan->ch_open) { mvwprintw (lbwin, r++, 2, "***** Port is Busy."); wrefresh(lbwin); test_cases++; sleep(1); goto user_input; } for (i = 0; i < 256; i++) { test_data[i] = (char) i; } test_data[TBUFSIZ]='\0'; /* Get port name. Can't run the test without it. */ if (DPAGetPortName(unit, node, chan, port, ttyname) == NULL) { mvwprintw (lbwin, r++, 2, "***** Loop Back Test Failure. Port has no known tty name"); test_cases++; wrefresh (lbwin); sleep(1); goto user_input; } sprintf(string, "/dev/%s", ttyname); if( (rwfd = tty_open(string, &sv_tios )) < 0 ) { test_cases++; goto user_input; } tcflush(rwfd, TCIOFLUSH); if ((i = test_send (test_data, TBUFSIZ, rwfd)) != 0) { mvwprintw (lbwin, r++, 2, "***** Loop Back Test Failure=%d, Sending %d Bytes", i, TBUFSIZ); wrefresh (lbwin); tty_close (rwfd, &sv_tios); test_cases++; goto user_input; } mvwprintw (lbwin, r++, 2, "Loop Back: %d Bytes Sent.", TBUFSIZ); wrefresh (lbwin); mvwprintw (lbwin, r++, 2, "Loop Back: Receiving %d Bytes.", TBUFSIZ); wrefresh (lbwin); if ((i = test_recv (read_data, TBUFSIZ, 5, rwfd)) != TBUFSIZ) { mvwprintw (lbwin, r++, 2, "***** Loop Back Failure=%d Receiving %d bytes.", i, TBUFSIZ); wrefresh (lbwin); tty_close (rwfd, &sv_tios); test_cases++; goto user_input; } /* Reset termios as before and close channel */ tty_close (rwfd, &sv_tios); mvwprintw (lbwin, r++, 2, "Loop Back: Verifying %d bytes.", TBUFSIZ); wrefresh (lbwin); if (memcmp (test_data, read_data, TBUFSIZ)) { mvwprintw (lbwin, r++, 2, "***** Loop Back Failure Verifying %d Bytes.", TBUFSIZ); mvwprintw (lbwin, r++, 2, "***** Data Incorrectly Transferred."); wrefresh (lbwin); test_cases++; goto user_input; } else { mvwprintw (lbwin, r++, 2, "Loop Back: Test Passed."); wrefresh (lbwin); test_cases++; test_passes++; } user_input: option = getch(); /* * If the user hasn't selected anything, loop. * Otherwise, break. */ switch (option) { case EOF: break; case '': refresh_screen (); option = EOF; break; #ifdef KEY_PRINT case KEY_PRINT: #endif case '': screen_save (LBWin, logfile); touchwin (lbwin); wrefresh (lbwin); update_panels (); doupdate (); option = EOF; break; default: break; } /* End Case */ } /* End While */ hide_panel (GetPan(LBWin)); update_panels (); doupdate (); return; }
int cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct session *s; struct client *c; const char *update; char *overrides, *cause; u_int i; if (RB_EMPTY(&sessions)) { ctx->error(ctx, "no sessions"); return (-1); } if ((s = cmd_find_session(ctx, args_get(args, 't'), 1)) == NULL) return (-1); if (ctx->cmdclient == NULL && ctx->curclient == NULL) return (0); if (ctx->cmdclient == NULL) { if (args_has(self->args, 'd')) { /* * Can't use server_write_session in case attaching to * the same session as currently attached to. */ for (i = 0; i < ARRAY_LENGTH(&clients); i++) { c = ARRAY_ITEM(&clients, i); if (c == NULL || c->session != s) continue; if (c == ctx->curclient) continue; server_write_client(c, MSG_DETACH, NULL, 0); } } ctx->curclient->session = s; session_update_activity(s); server_redraw_client(ctx->curclient); } else { if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) { ctx->error(ctx, "not a terminal"); return (-1); } overrides = options_get_string(&s->options, "terminal-overrides"); if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) { ctx->error(ctx, "terminal open failed: %s", cause); xfree(cause); return (-1); } if (args_has(self->args, 'r')) ctx->cmdclient->flags |= CLIENT_READONLY; if (args_has(self->args, 'd')) server_write_session(s, MSG_DETACH, NULL, 0); ctx->cmdclient->session = s; session_update_activity(s); server_write_client(ctx->cmdclient, MSG_READY, NULL, 0); update = options_get_string(&s->options, "update-environment"); environ_update(update, &ctx->cmdclient->environ, &s->environ); server_redraw_client(ctx->cmdclient); } recalculate_sizes(); server_update_socket(); return (1); /* 1 means don't tell command client to exit */ }
int pty_open(uint8_t minor, uint16_t flag) { return tty_open(minor + PTY_OFFSET, flag); }