mirror of
https://github.com/zhaojh329/rtty.git
synced 2026-02-27 09:53:17 +08:00
chore: earlier check args
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
+21
-5
@@ -29,6 +29,7 @@
|
||||
#include <glob.h>
|
||||
|
||||
#include "log/log.h"
|
||||
#include "utils.h"
|
||||
#include "rtty.h"
|
||||
|
||||
enum {
|
||||
@@ -235,6 +236,26 @@ int main(int argc, char **argv)
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
if (!rtty.devid) {
|
||||
log_err("you must specify an id for your device\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!valid_id(rtty.devid)) {
|
||||
log_err("invalid device id\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (find_login(rtty.login_path, sizeof(rtty.login_path) - 1) < 0) {
|
||||
log_err("the program 'login' is not found\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (getuid() > 0) {
|
||||
log_err("Operation not permitted, must be run as root\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (background && daemon(0, 0))
|
||||
log_err("Can't run in the background: %s\n", strerror(errno));
|
||||
|
||||
@@ -243,11 +264,6 @@ int main(int argc, char **argv)
|
||||
|
||||
log_info("rtty version %s\n", RTTY_VERSION_STRING);
|
||||
|
||||
if (getuid() > 0) {
|
||||
log_err("Operation not permitted, must be run as root\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ev_signal_init(&signal_watcher, signal_cb, SIGINT);
|
||||
ev_signal_start(loop, &signal_watcher);
|
||||
|
||||
|
||||
+2
-20
@@ -34,12 +34,9 @@
|
||||
#include "file.h"
|
||||
#include "rtty.h"
|
||||
#include "list.h"
|
||||
#include "utils.h"
|
||||
#include "command.h"
|
||||
#include "log/log.h"
|
||||
|
||||
static char login_path[128]; /* /bin/login */
|
||||
|
||||
static void del_tty(struct tty *tty)
|
||||
{
|
||||
struct rtty *rtty = tty->rtty;
|
||||
@@ -194,9 +191,9 @@ static void tty_login(struct rtty *rtty, const char *sid)
|
||||
|
||||
if (pid == 0) {
|
||||
if (rtty->username)
|
||||
execl(login_path, "login", "-f", rtty->username, NULL);
|
||||
execl(rtty->login_path, "login", "-f", rtty->username, NULL);
|
||||
else
|
||||
execl(login_path, "login", NULL);
|
||||
execl(rtty->login_path, "login", NULL);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
@@ -762,21 +759,6 @@ static void rtty_timer_cb(struct ev_loop *loop, struct ev_timer *w, int revents)
|
||||
|
||||
int rtty_start(struct rtty *rtty)
|
||||
{
|
||||
if (!rtty->devid) {
|
||||
log_err("you must specify an id for your device\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!valid_id(rtty->devid)) {
|
||||
log_err("invalid device id\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (find_login(login_path, sizeof(login_path) - 1) < 0) {
|
||||
log_err("the program 'login' is not found\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rtty_run_state(RTTY_STATE_DISCONNECTED);
|
||||
|
||||
ev_init(&rtty->tmr, rtty_timer_cb);
|
||||
|
||||
@@ -92,6 +92,7 @@ struct tty {
|
||||
};
|
||||
|
||||
struct rtty {
|
||||
char login_path[128]; /* /bin/login */
|
||||
const char *host;
|
||||
int port;
|
||||
int sock;
|
||||
|
||||
Reference in New Issue
Block a user