mirror of
https://github.com/upa/mscp.git
synced 2026-03-12 19:27:34 +08:00
compilable in linux
This commit is contained in:
@@ -9,4 +9,4 @@ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
|
|||||||
add_executable(sscp src/main.c src/platform.c src/ssh.c src/file.c)
|
add_executable(sscp src/main.c src/platform.c src/ssh.c src/file.c)
|
||||||
target_include_directories(sscp PUBLIC ./src /usr/local/include)
|
target_include_directories(sscp PUBLIC ./src /usr/local/include)
|
||||||
target_link_directories(sscp PUBLIC /usr/local/lib)
|
target_link_directories(sscp PUBLIC /usr/local/lib)
|
||||||
target_link_libraries(sscp ssh)
|
target_link_libraries(sscp ssh pthread m)
|
||||||
|
|||||||
@@ -306,7 +306,9 @@ int file_fill_dst(char *target, struct list_head *file_list)
|
|||||||
|
|
||||||
list_for_each_entry(f, file_list, list) {
|
list_for_each_entry(f, file_list, list) {
|
||||||
f->dst_remote = dst_remote;
|
f->dst_remote = dst_remote;
|
||||||
snprintf(f->dst_path, PATH_MAX, "%s/%s", dst_path, f->path);
|
strncat(f->dst_path, dst_path, PATH_MAX);
|
||||||
|
strncat(f->dst_path, "/", PATH_MAX);
|
||||||
|
strncat(f->dst_path, f->path, PATH_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
11
src/main.c
11
src/main.c
@@ -307,6 +307,10 @@ int main(int argc, char **argv)
|
|||||||
struct sscp_thread *t = &threads[n];
|
struct sscp_thread *t = &threads[n];
|
||||||
t->sscp = &sscp;
|
t->sscp = &sscp;
|
||||||
t->finished = false;
|
t->finished = false;
|
||||||
|
t->sftp = ssh_make_sftp_session(sscp.host, sscp.opts);
|
||||||
|
if (!t->sftp)
|
||||||
|
goto join_out;
|
||||||
|
|
||||||
ret = pthread_create(&t->tid, NULL, sscp_copy_thread, t);
|
ret = pthread_create(&t->tid, NULL, sscp_copy_thread, t);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
pr_err("pthread_create error: %d\n", ret);
|
pr_err("pthread_create error: %d\n", ret);
|
||||||
@@ -352,14 +356,9 @@ void *sscp_copy_thread(void *arg)
|
|||||||
{
|
{
|
||||||
struct sscp_thread *t = arg;
|
struct sscp_thread *t = arg;
|
||||||
struct sscp *sscp = t->sscp;
|
struct sscp *sscp = t->sscp;
|
||||||
sftp_session sftp;
|
sftp_session sftp = t->sftp;
|
||||||
struct chunk *c;
|
struct chunk *c;
|
||||||
|
|
||||||
/* create sftp session */
|
|
||||||
sftp = ssh_make_sftp_session(sscp->host, sscp->opts);
|
|
||||||
if (!sftp)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||||
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
|
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
|
||||||
pthread_cleanup_push(sscp_copy_thread_cleanup, t);
|
pthread_cleanup_push(sscp_copy_thread_cleanup, t);
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
#include <util.h>
|
|
||||||
#include <platform.h>
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#elif linux
|
#elif linux
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <sched.h>
|
||||||
#else
|
#else
|
||||||
#error unsupported platform
|
#error unsupported platform
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <util.h>
|
||||||
|
#include <platform.h>
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
int nr_cpus()
|
int nr_cpus()
|
||||||
@@ -25,3 +26,13 @@ int nr_cpus()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef linux
|
||||||
|
int nr_cpus()
|
||||||
|
{
|
||||||
|
cpu_set_t cpu_set;
|
||||||
|
if (sched_getaffinity(0, sizeof(cpu_set_t), &cpu_set) == 0)
|
||||||
|
return CPU_COUNT(&cpu_set);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user