mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Port the commit to master to fix PDF Output with ebook-convert via symlink on macOS
This commit is contained in:
parent
1c9342d32a
commit
2a2f641856
@ -9,9 +9,22 @@
|
||||
#define fatal(...) { fprintf(stderr, __VA_ARGS__); exit(EXIT_FAILURE); }
|
||||
#define arraysz(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char * const *argv) {
|
||||
run(PROGRAM, MODULE, FUNCTION, IS_GUI, argc, argv);
|
||||
char pathbuf[PROC_PIDPATHINFO_MAXSIZE], realpath_buf[PROC_PIDPATHINFO_MAXSIZE * 5];
|
||||
pid_t pid = getpid();
|
||||
int ret = proc_pidpath(pid, pathbuf, arraysz(pathbuf));
|
||||
if (ret <= 0) fatal("failed to get executable path for current pid with error: %s", strerror(errno));
|
||||
char *path = realpath(pathbuf, realpath_buf);
|
||||
if (path == NULL) fatal("failed to get realpath for executable path with error: %s", strerror(errno));
|
||||
// We re-exec using an absolute path because the Qt WebEngine sandbox does not work
|
||||
// when running via symlink
|
||||
if (!IS_GUI && strcmp(PROGRAM, "calibre-parallel") != 0 && strcmp(argv[0], path) != 0) {
|
||||
char* new_argv[1024] = {0};
|
||||
new_argv[0] = path;
|
||||
for (int i = 1; i < argc && i < arraysz(new_argv) - 1; i++) new_argv[i] = argv[i];
|
||||
execv(path, new_argv);
|
||||
}
|
||||
run(PROGRAM, MODULE, FUNCTION, IS_GUI, argc, argv, path);
|
||||
return 0;
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include "../run-python.h"
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <mach-o/dyld.h>
|
||||
#include <libproc.h>
|
||||
|
||||
#define EXPORT __attribute__((visibility("default")))
|
||||
|
||||
@ -28,13 +27,7 @@ set_env_vars(const char* contents_path) {
|
||||
}
|
||||
|
||||
static void
|
||||
get_paths() {
|
||||
char pathbuf[PROC_PIDPATHINFO_MAXSIZE], realpath_buf[PROC_PIDPATHINFO_MAXSIZE * 5];
|
||||
pid_t pid = getpid();
|
||||
int ret = proc_pidpath(pid, pathbuf, sizeof(pathbuf));
|
||||
if (ret <= 0) fatal("failed to get executable path for current pid with error: %s", strerror(errno));
|
||||
char *path = realpath(pathbuf, realpath_buf);
|
||||
if (path == NULL) fatal("failed to get realpath for executable path with error: %s", strerror(errno));
|
||||
get_paths(char *path) {
|
||||
decode_char_buf(path, interpreter_data.exe_path);
|
||||
for (unsigned i = 0; i < 3; i++) {
|
||||
char *t = rindex(path, '/');
|
||||
@ -68,11 +61,11 @@ get_paths() {
|
||||
|
||||
EXPORT
|
||||
void
|
||||
run(const wchar_t *program, const wchar_t *module, const wchar_t *function, bool gui_app, int argc, char * const *argv) {
|
||||
run(const wchar_t *program, const wchar_t *module, const wchar_t *function, bool gui_app, int argc, char * const *argv, char* exe_path) {
|
||||
interpreter_data.argc = argc;
|
||||
interpreter_data.argv = argv;
|
||||
interpreter_data.basename = program; interpreter_data.module = module; interpreter_data.function = function;
|
||||
pre_initialize_interpreter(gui_app);
|
||||
get_paths();
|
||||
get_paths(exe_path);
|
||||
run_interpreter();
|
||||
}
|
||||
|
@ -2,4 +2,4 @@
|
||||
#include <wchar.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void run(const wchar_t *program, const wchar_t *module, const wchar_t *function, bool is_gui, int argc, char * const *argv);
|
||||
void run(const wchar_t *program, const wchar_t *module, const wchar_t *function, bool is_gui, int argc, char * const *argv, char* exe_path);
|
||||
|
Loading…
x
Reference in New Issue
Block a user