Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <stdint.h>
- #include <inttypes.h>
- #include <sys/wait.h>
- #include <linux/limits.h>
- #include <time.h>
- extern char **environ;
- char *tmp_path (void)
- {
- char *x;
- const char *default_dir = "/tmp";
- if (!(x = getenv("XDG_RUNTIME_DIR"))) {
- if (!(x = getenv("TMPDIR"))) {
- return (char *)default_dir;
- } else {
- return x;
- }
- } else {
- return x;
- }
- }
- int main(int argc, char *argv[])
- {
- pid_t pid;
- char *x;
- int status;
- char path[PATH_MAX], execfile[PATH_MAX], fname[PATH_MAX];
- snprintf(path,PATH_MAX,"%s",tmp_path());
- printf("%s\n",path);
- pid = getpid();
- snprintf(fname,PATH_MAX,"%s/_tmp_%d_.py",path,pid);
- snprintf(execfile,PATH_MAX,"%s/_tmp_%d_.py",path,pid);
- printf("%s\n",fname);
- fflush(stdout);
- int fd = open(fname, O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC,0700);
- if (fd == -1) {
- exit(1);
- }
- //printf("OK");
- fflush(stdout);
- dup2(fd,1);
- close(fd);
- printf("#!/bin/bash\n#!/usr/bin/env python\nprint(");
- for (int i = 1; i < argc - 1; i++) {
- printf("%s*",argv[i]);
- }
- printf("%s)",argv[argc - 1]);
- fflush(stdout);
- execl("/bin/bash", "bash", "-c", execfile, NULL);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement