Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/zhaojh329/rtty
Browse files Browse the repository at this point in the history
  • Loading branch information
Jianhui Zhao committed Mar 16, 2018
2 parents 6a384f6 + fe7938f commit eb9519e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[4]: https://github.com/zhaojh329/rtty/pulls
[5]: https://img.shields.io/badge/Issues-welcome-brightgreen.svg?style=plastic
[6]: https://github.com/zhaojh329/rtty/issues/new
[7]: https://img.shields.io/badge/release-4.1.0-blue.svg?style=plastic
[7]: https://img.shields.io/badge/release-4.1.1-blue.svg?style=plastic
[8]: https://github.com/zhaojh329/rtty/releases
[9]: https://travis-ci.org/zhaojh329/rtty.svg?branch=master
[10]: https://travis-ci.org/zhaojh329/rtty
Expand Down Expand Up @@ -160,7 +160,7 @@ Automatic login: `https://your-server:5912/?id=device-id&username=device-usernam
Open the context menu with the shortcut key: Ctrl+Shift+f

## Execute a command remote
`curl -k https://your-server:5912/cmd -d '{"devid":"test","cmd":"ls","username":"test","password":"123456"}'`
`curl -k https://your-server:5912/cmd -d '{"devid":"test","username":"test","password":"123456","cmd":"ls","params":["/"],"env":[]}'`

# Contributing
If you would like to help making [rtty](https://github.com/zhaojh329/rtty) better,
Expand Down
4 changes: 2 additions & 2 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[4]: https://github.com/zhaojh329/rtty/pulls
[5]: https://img.shields.io/badge/Issues-welcome-brightgreen.svg?style=plastic
[6]: https://github.com/zhaojh329/rtty/issues/new
[7]: https://img.shields.io/badge/release-4.1.0-blue.svg?style=plastic
[7]: https://img.shields.io/badge/release-4.1.1-blue.svg?style=plastic
[8]: https://github.com/zhaojh329/rtty/releases
[9]: https://travis-ci.org/zhaojh329/rtty.svg?branch=master
[10]: https://travis-ci.org/zhaojh329/rtty
Expand Down Expand Up @@ -152,7 +152,7 @@ rtty非常适合远程维护你的或者你公司的部署在全球各地的成
使用快捷键打开菜单: Ctrl+Shift+f

## 远程执行命令
`curl -k https://your-server:5912/cmd -d '{"devid":"test","cmd":"ls","username":"test","password":"123456"}'`
`curl -k https://your-server:5912/cmd -d '{"devid":"test","username":"test","password":"123456","cmd":"ls","params":["/"],"env":[]}'`

# 贡献代码
如果你想帮助[rtty](https://github.com/zhaojh329/rtty)变得更好,请参考
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ add_definitions(-O -Wall -Werror --std=gnu99 -D_GNU_SOURCE)
# The version number.
set(RTTY_VERSION_MAJOR 4)
set(RTTY_VERSION_MINOR 1)
set(RTTY_VERSION_PATCH 0)
set(RTTY_VERSION_PATCH 1)

# Check the third party Libraries
find_package(Libubox REQUIRED)
Expand Down
34 changes: 23 additions & 11 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ void command_init()
q.max_running_tasks = 5;
}

static void free_command(struct command *c)
{
ustream_free(&c->opipe.stream);
ustream_free(&c->epipe.stream);

close(c->opipe.fd.fd);
close(c->epipe.fd.fd);

free(c->arg);
free(c->env);
free(c);
}

static void ustream_to_blobmsg(struct ustream *s, struct blob_buf *buf, const char *name)
{
int len;
Expand Down Expand Up @@ -120,15 +133,7 @@ static void command_reply(struct command *c, int err)

send_command_reply(buf, c->ws);

ustream_free(&c->opipe.stream);
ustream_free(&c->epipe.stream);

close(c->opipe.fd.fd);
close(c->epipe.fd.fd);

free(c->arg);
free(c->env);
free(c);
free_command(c);
}

static void process_opipe_read_cb(struct ustream *s, int bytes)
Expand Down Expand Up @@ -206,11 +211,18 @@ static void runqueue_proc_cb(struct uloop_process *p, int ret)
struct runqueue_process *t = container_of(p, struct runqueue_process, proc);
struct command *c = container_of(t, struct command, proc);

c->code = WEXITSTATUS(ret);
if (c->code == -1) {
/* The server will response timeout to user */
ULOG_ERR("Run `%s` timeout\n", c->cmd);
free_command(c);
goto TIMEOUT;
}

c->code = WEXITSTATUS(ret);
ustream_poll(&c->opipe.stream);
ustream_poll(&c->epipe.stream);

TIMEOUT:
runqueue_task_complete(&t->task);
}

Expand Down Expand Up @@ -302,7 +314,7 @@ static void run_command_cancel(struct runqueue *q, struct runqueue_task *t, int
{
struct command *c = container_of(t, struct command, proc.task);

command_reply(c, COMMAND_ERR_TIMEOUT);
c->code = -1; /* Timeout */
runqueue_process_cancel_cb(q, t, type);
}

Expand Down

0 comments on commit eb9519e

Please sign in to comment.