summaryrefslogtreecommitdiffstats
path: root/kernel/sys.c
AgeCommit message (Expand)Author
2019-01-14kernel/sys.c: Clarify that UNAME26 does not generate unique versions anymoreJonathan Neuschäfer
2019-01-03Remove 'type' argument from access_ok() functionLinus Torvalds
2018-12-13arm64: add prctl control for resetting ptrauth keysKristina Martsenko
2018-09-20kernel/sys.c: remove duplicated includeYueHaibing
2018-08-24Merge branch 'userns-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/...Linus Torvalds
2018-08-11sys: don't hold uts_sem while accessing userspace memoryJann Horn
2018-06-19sysinfo: Remove get_monotonic_boottime()Arnd Bergmann
2018-06-07mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_structYang Shi
2018-05-25kernel/sys.c: fix potential Spectre v1 issueGustavo A. R. Silva
2018-05-03nospec: Allow getting/setting on non-current taskKees Cook
2018-05-03prctl: Add speculation control prctlsThomas Gleixner
2018-04-02kernel: add ksys_setsid() helper; remove in-kernel call to sys_setsid()Dominik Brodowski
2018-04-02kernel: provide ksys_*() wrappers for syscalls called by kernel/uid16.cDominik Brodowski
2018-04-02kernel: add do_getpgid() helper; remove internal call to sys_getpgid()Dominik Brodowski
2017-12-14fix typo in assignment of fs default overflow gidWolffhardt Schwabe
2017-11-15Merge tag 'arm64-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/a...Linus Torvalds
2017-11-03arm64/sve: Add prctl controls for userspace vector length managementDave Martin
2017-11-02License cleanup: add SPDX GPL-2.0 license identifier to files with no licenseGreg Kroah-Hartman
2017-07-20prctl: Allow local CAP_SYS_ADMIN changing exe_fileKirill Tkhai
2017-07-12fix a braino in compat_sys_getrlimit()Al Viro
2017-07-10mm: make PR_SET_THP_DISABLE immediately activeMichal Hocko
2017-07-06Merge branch 'misc.compat' of git://git.kernel.org/pub/scm/linux/kernel/git/v...Linus Torvalds
2017-06-09getrlimit()/setrlimit(): move compat to nativeAl Viro
2017-06-09times(2): move compat to nativeAl Viro
2017-05-27take compat_sys_old_getrlimit() to native syscallAl Viro
2017-05-21wait4(2)/waitid(2): separate copying rusage to userlandAl Viro
2017-05-05Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebi...Linus Torvalds
2017-04-21rlimit: Properly call security_task_setrlimitEric W. Biederman
2017-03-06prlimit,security,selinux: add a security hook for prlimitStephen Smalley
2017-03-02sched/headers: Prepare to move cputime functionality from <linux/sched.h> int...Ingo Molnar
2017-03-02sched/headers: Prepare for new header dependencies before moving code to <lin...Ingo Molnar
2017-03-02sched/headers: Prepare for new header dependencies before moving code to <lin...Ingo Molnar
2017-03-02sched/headers: Prepare for new header dependencies before moving code to <lin...Ingo Molnar
2017-03-02sched/headers: Prepare for new header dependencies before moving code to <lin...Ingo Molnar
2017-03-02sched/headers: Prepare for new header dependencies before moving code to <lin...Ingo Molnar
2017-03-02sched/headers: Prepare for new header dependencies before moving code to <lin...Ingo Molnar
2017-02-23Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebi...Linus Torvalds
2017-02-03prctl: propagate has_child_subreaper flag to every descendantPavel Tikhomirov
2017-02-01sched/cputime: Convert task/group cputime to nsecsFrederic Weisbecker
2016-12-24Replace <asm/uaccess.h> with <linux/uaccess.h> globallyLinus Torvalds
2016-12-12Merge branch 'akpm' (patches from Andrew)Linus Torvalds
2016-12-12prctl: remove one-shot limitation for changing exe linkStanislav Kinsburskiy
2016-11-16posix-timers: Make them configurableNicolas Pitre
2016-05-23prctl: make PR_SET_THP_DISABLE wait for mmap_sem killableMichal Hocko
2016-03-17timer: convert timer_slack_ns from unsigned long to u64John Stultz
2016-01-20prctl: take mmap sem for writing to protect against othersMateusz Guzik
2015-11-06pidns: fix set/getpriority and ioprio_set/get in PRIO_USER modeBen Segall
2015-07-10vfs: Commit to never having exectuables on proc and sysfs.Eric W. Biederman
2015-06-25prctl: more prctl(PR_SET_MM_*) checksAlexey Dobriyan
2015-06-09x86/mpx: Clean up the code by not passing a task pointer around when unnecessaryDave Hansen
>390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
/* vifm
 * Copyright (C) 2023 xaizek.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "vifm.h"

#include <unistd.h> /* isatty() */

#include "../cfg/info.h"
#include "../engine/options.h"
#include "../modes/dialogs/msg_dialog.h"
#include "../modes/cmdline.h"
#include "../ui/statusbar.h"
#include "../utils/fs.h"
#include "../utils/path.h"
#include "../utils/str.h"
#include "../utils/utils.h"
#include "../event_loop.h"
#include "../filelist.h"
#include "../filename_modifiers.h"
#include "../running.h"
#include "lua/lua.h"
#include "lua/lauxlib.h"
#include "api.h"
#include "common.h"
#include "vifm_abbrevs.h"
#include "vifm_cmds.h"
#include "vifm_events.h"
#include "vifm_handlers.h"
#include "vifm_keys.h"
#include "vifm_tabs.h"
#include "vifm_viewcolumns.h"
#include "vifmjob.h"
#include "vifmview.h"
#include "vlua_state.h"

/* Lua API version. */
#define API_VER_MAJOR 0
#define API_VER_MINOR 1
#define API_VER_PATCH 0

/*
 * This unit contains generic part of `vifm` global table.  Plugin-specific
 * things are in vlua unit.
 *
 * Implementation for small things are here, others are in corresponding vifm_*
 * or type-specific vifm* units and are only initialized here.
 */

/* Data passed to prompt callback in vifm.input(). */
typedef struct
{
	int quit;       /* Exit flag for event loop. */
	char *response; /* Result of the prompt. */
}
input_cb_data_t;

static int VLUA_API(vifm_errordialog)(lua_State *lua);
static int VLUA_API(vifm_escape)(lua_State *lua);
static int VLUA_API(vifm_executable)(lua_State *lua);
static int VLUA_API(vifm_exists)(lua_State *lua);
static int VLUA_API(vifm_expand)(lua_State *lua);
static int VLUA_API(vifm_fnamemodify)(lua_State *lua);
static int VLUA_API(vifm_input)(lua_State *lua);
static int VLUA_API(vifm_makepath)(lua_State *lua);
static int VLUA_API(vifm_run)(lua_State *lua);
static int VLUA_API(vifm_sessions_current)(lua_State *lua);
static int VLUA_API(vifm_stdout)(lua_State *lua);
static int VLUA_IMPL(stdout_closef)(lua_State *lua);

static int VLUA_API(api_is_at_least)(lua_State *lua);
static int VLUA_API(api_has)(lua_State *lua);

static int VLUA_API(opts_global_index)(lua_State *lua);
static int VLUA_API(opts_global_newindex)(lua_State *lua);

static int VLUA_API(sb_info)(lua_State *lua);
static int VLUA_API(sb_error)(lua_State *lua);
static int VLUA_API(sb_quick)(lua_State *lua);

VLUA_DECLARE_SAFE(vifm_errordialog);
VLUA_DECLARE_SAFE(vifm_escape);
VLUA_DECLARE_SAFE(vifm_executable);
VLUA_DECLARE_SAFE(vifm_exists);
VLUA_DECLARE_SAFE(vifm_expand);
VLUA_DECLARE_SAFE(vifm_fnamemodify);
VLUA_DECLARE_SAFE(vifm_input);
VLUA_DECLARE_SAFE(vifm_makepath);
VLUA_DECLARE_SAFE(vifm_run);
VLUA_DECLARE_SAFE(vifm_sessions_current);
VLUA_DECLARE_SAFE(vifm_stdout);

VLUA_DECLARE_SAFE(api_is_at_least);
VLUA_DECLARE_SAFE(api_has);

VLUA_DECLARE_SAFE(opts_global_index);
VLUA_DECLARE_UNSAFE(opts_global_newindex);

VLUA_DECLARE_SAFE(sb_info);
VLUA_DECLARE_SAFE(sb_error);
VLUA_DECLARE_SAFE(sb_quick);

/* These are defined in other units. */
VLUA_DECLARE_UNSAFE(vifm_addcolumntype);
VLUA_DECLARE_SAFE(vifm_addhandler);
VLUA_DECLARE_SAFE(vifmview_currview);
VLUA_DECLARE_SAFE(vifmview_otherview);
VLUA_DECLARE_SAFE(vifmjob_new);

static void input_builtin_cb(const char response[], void *arg);

/* Functions of `vifm` global table. */
static const struct luaL_Reg vifm_methods[] = {
	{ "errordialog",   VLUA_REF(vifm_errordialog)   },
	{ "escape",        VLUA_REF(vifm_escape)        },
	{ "executable",    VLUA_REF(vifm_executable)    },
	{ "exists",        VLUA_REF(vifm_exists)        },
	{ "expand",        VLUA_REF(vifm_expand)        },
	{ "fnamemodify",   VLUA_REF(vifm_fnamemodify)   },
	{ "input",         VLUA_REF(vifm_input)         },
	{ "makepath",      VLUA_REF(vifm_makepath)      },
	{ "run",           VLUA_REF(vifm_run)           },
	{ "stdout",        VLUA_REF(vifm_stdout)        },

	/* Defined in other units. */
	{ "addcolumntype", VLUA_REF(vifm_addcolumntype) },
	{ "addhandler",    VLUA_REF(vifm_addhandler)    },
	{ "currview",      VLUA_REF(vifmview_currview)  },
	{ "otherview",     VLUA_REF(vifmview_otherview) },
	{ "startjob",      VLUA_REF(vifmjob_new)        },

	{ NULL,            NULL                         }
};

/* Functions of `vifm.sb` table. */
static const struct luaL_Reg sb_methods[] = {
	{ "info",   VLUA_REF(sb_info)  },
	{ "error",  VLUA_REF(sb_error) },
	{ "quick",  VLUA_REF(sb_quick) },
	{ NULL,     NULL               }
};

void
vifm_init(lua_State *lua)
{
	vifmjob_init(lua);
	vifmview_init(lua);

	luaL_newlib(lua, vifm_methods);

	/* Setup vifm.abbrevs. */
	vifm_abbrevs_init(lua);
	lua_setfield(lua, -2, "abbrevs");

	/* Setup vifm.cmds. */
	vifm_cmds_init(lua);
	lua_setfield(lua, -2, "cmds");

	/* Setup vifm.events. */
	vifm_events_init(lua);
	lua_setfield(lua, -2, "events");

	/* Setup vifm.keys. */
	vifm_keys_init(lua);
	lua_setfield(lua, -2, "keys");

	/* Setup vifm.tabs. */
	vifm_tabs_init(lua);
	lua_setfield(lua, -2, "tabs");

	/* Setup vifm.opts. */
	lua_createtable(lua, /*narr=*/0, /*nrec=*/1); /* vifm.opts */
	lua_newtable(lua);                            /* vifm.opts.global */
	vlua_cmn_make_metatable(lua, /*name=*/NULL);  /* for vifm.opts.global */
	lua_pushcfunction(lua, VLUA_REF(opts_global_index));
	lua_setfield(lua, -2, "__index");
	lua_pushcfunction(lua, VLUA_REF(opts_global_newindex));
	lua_setfield(lua, -2, "__newindex");
	lua_setmetatable(lua, -2);       /* vifm.opts.global */
	lua_setfield(lua, -2, "global"); /* vifm.opts.global */
	lua_setfield(lua, -2, "opts");   /* vifm.opts */

	/* Setup vifm.plugins. */
	lua_createtable(lua, /*narr=*/0, /*nrec=*/1); /* vifm.plugins */
	lua_newtable(lua);                            /* vifm.plugins.all */
	lua_setfield(lua, -2, "all");
	lua_setfield(lua, -2, "plugins");

	/* Setup vifm.version. */
	lua_createtable(lua, /*narr=*/0, /*nrec=*/2); /* vifm.version */
	lua_createtable(lua, /*narr=*/0, /*nrec=*/1); /* vifm.app */
	lua_pushstring(lua, VERSION);
	lua_setfield(lua, -2, "str");                 /* vifm.app.str */
	lua_setfield(lua, -2, "app");                 /* vifm.app */
	lua_createtable(lua, /*narr=*/0, /*nrec=*/5); /* vifm.api */
	lua_pushinteger(lua, API_VER_MAJOR);
	lua_setfield(lua, -2, "major");               /* vifm.api.major */
	lua_pushinteger(lua, API_VER_MINOR);
	lua_setfield(lua, -2, "minor");               /* vifm.api.minor */
	lua_pushinteger(lua, API_VER_PATCH);
	lua_setfield(lua, -2, "patch");               /* vifm.api.patch */
	lua_pushcfunction(lua, VLUA_REF(api_has));
	lua_setfield(lua, -2, "has");                 /* vifm.api.has */
	lua_pushcfunction(lua, VLUA_REF(api_is_at_least));
	lua_setfield(lua, -2, "atleast");             /* vifm.api.atleast */
	lua_setfield(lua, -2, "api");                 /* vifm.api */
	lua_setfield(lua, -2, "version");             /* vifm.version