2017-11-28 60 views
-1

CUPS 인쇄 시스템을 만들려고합니다. 프린터 상태, 얼마나 많은 페이지가 출력되는지 알고 싶습니다.CUPS 인쇄 파일 세분화 오류

이렇게하려면 CUPS 예제에서 주어진 예제 프로그램을 실행하고 있습니다. 내가 얻고 ./myout

을 실행하려고하면

#include <cups/cups.h> 
#include <stdio.h> 


int main(){ 

int num_options; 
cups_option_t *options; 

cups_dest_t *dests; 
int num_dests = cupsGetDests(&dests); 
cups_dest_t *dest = cupsGetDest("name", NULL, num_dests, dests); 
int job_id; 

/* Print a single file */ 
job_id = cupsPrintFile(dest->name, "testfile.txt", "Test Print", num_options, options); 

cupsFreeDests(num_dests, dests); 

return 0; 
} 

가 나는 gcc myfile.c -o myout -lcups

를 사용하여 컴파일

분할 오류

나는 나무 딸기-PI (3)를 사용하고 있습니다 내 CUPS 서버로 보드.

미리 감사드립니다.

+0

개발 환경에 gdb가 있습니까? – lockcmpxchg8b

+0

@ lockcmpxchg8b 예. – Sachith

+0

실행 방법을 안다면 SIGSEGV에서 깨질 것이고,'where' 명령은 segv 될 때 어디에서 실행되었는지에 대한 스택 추적을 줄 것입니다. 디버그 모드로 컴파일하면 더 좋습니다. – lockcmpxchg8b

답변

2

dest이 유효하지 않은 주소를 가리키고 있습니다.

cups_dest_t *dest; // declared but not initialized or assigned afterwards 

것은 그래서 (... cupsPrintFile(dest->name)를 참조 해제하는 것은 UB하고 세그먼트 폴트가 발생할 수 있습니다.


은 ( here에서 촬영) 당신이 그것을 사용해야하는 방법입니다

#include <cups/cups.h> 

cups_dest_t *dests; 
int num_dests = cupsGetDests(&dests); 
cups_dest_t *dest = cupsGetDest("name", NULL, num_dests, dests); 

/* do something with dest */ 

cupsFreeDests(num_dests, dests); 

업데이트 :

귀하의 코드는 변수의 일부를 처리하지 않습니다

(즉 그것들을 초기화되지 않은 채로 남겨 두었습니다 - 나쁜). 내가 처음 보는 것은 cups_option_t *options;입니다. 모든 변수를 처리하고, 이것이 작동하지 않는다면 - 디버그하십시오.

int main(){ 

int num_options; 
cups_option_t *options; // add a call to "cupsAddOption("first", "value", num_options, &options);" 

cups_dest_t *dests; 
int num_dests = cupsGetDests(&dests); 
cups_dest_t *dest = cupsGetDest("name", NULL, num_dests, dests); 
int job_id; 

/* Print a single file */ 
job_id = cupsPrintFile(dest->name, "testfile.txt", "Test Print", num_options, options); // options is used here but is uninitialized 

cupsFreeDests(num_dests, dests); 

return 0; 
} 
+0

여전히 동일한 오류가 발생합니다. – Sachith

+1

업데이트 된 코드 보이기 – CIsForCookies

+0

'options'와'num_options'도 초기화되지 않았습니다 ... – lockcmpxchg8b