关于打印过程中强制移除打印机的处理
在打印過程中,強制拔除打印機會出現如下狀況:
Hpijs會輸出這個信息:unable?to?send?DeviceStatus:?Bad?file?descriptor:?hplip_api.c?641
一直循環。
查得
$?man?errno?|?grep?"Bad?file?descriptor"
???????EBADF???????????Bad?file?descriptor?(POSIX.1)
解決方案1:
目前改善的是獲取hpijs的pid,將其kill?9之后可以結束不停的打印。但是也會打印幾百行后停止,所以優化的時候也要將hpijs中這句打印去掉。
static?int?print_stop_print(struct?print_device_t*?dev)?{
????int?ret?=?EXIT_FAILURE;
????//?hpijs?or?ijsgutenprint?pid.
????pid_t?pid?=?getPidByName("hpijs");
?
????if(pid?!=?0)
????????if(kill(pid,?9)?==?0)
????????????ret?=?EXIT_SUCCESS;
????????
????return?ret;
}
?
?
解決方案2:(最終采用的方案)
當出現這種情況的時候將自己kill掉。輸出一次信息,然后將自己kill掉。
if(errno?==?EBADF)
? ? exit(-1);?//?kill(getpid(),?9);
1.exit(-1);測試結果:
| GPL?Ghostscript?9.04?(2011-08-05) Copyright?(C)?2011?Artifex?Software,?Inc.??All?rights?reserved. This?software?comes?with?NO?WARRANTY:?see?the?file?PUBLIC?for?details. Processing?pages?1?through?1. Page?1 unable?to?write?to?output,?fd=6,?count=4096:?Input/output?error unable?to?write?to?output,?fd=6,?count=4096:?No?such?device unable?to?write?to?output,?fd=6,?count=4096:?No?such?device unable?to?write?to?output,?fd=6,?count=4096:?No?such?device unable?to?write?to?output,?fd=6,?count=4096:?No?such?device unable?to?send?DeviceStatus:?Bad?file?descriptor:?hplip_api.c?642 Error:?/ioerror?in?--showpage-- Operand?stack: ???1???true Execution?stack: ???%interp_exit???.runexec2???--nostringval--???--nostringval--???--nostringval--???2???%stopped_push???--nostringval--???--nostringval--???--nostringval--???false???1???%stopped_push???1910???1???3???%oparray_pop???1909???1???3???%oparray_pop???1893???1???3???%oparray_pop???--nostringval--???--nostringval--???2???1???1???--nostringval--???%for_pos_int_continue???--nostringval--???--nostringval--???1793???0???9???%oparray_pop???--nostringval--???--nostringval-- Dictionary?stack: ???--dict:1161/1684(ro)(G)--???--dict:1/20(G)--???--dict:82/200(L)--???--dict:82/200(L)--???--dict:108/127(ro)(G)--???--dict:291/300(ro)(G)--???--dict:23/30(L)--???--dict:6/8(L)--???--dict:22/40(L)-- Current?allocation?mode?is?local Last?OS?error:?32 GPL?Ghostscript?9.04:?Unrecoverable?error,?exit?code?1 |
?
2.kill(getpid(),?9)的測試結果:
????測試為無效。
?
sed命令:
1).添加#include?<errno.h>
sed?-i?'38s/#include?"hplip_api.h"/#include?<errno.h>\n#include?"hplip_api.h"/'?hplip_api.c
?
2.)添加
??????if(errno?==?EBADF)
????????exit(EXIT_FAILURE);
sed?-i?'643s/goto?mordor;/if(errno?==?EBADF)\n????????????exit(-1);\n????????goto?mordor;\n/'?hplip_api.c
?
擴展:
????hpijs是一個服務,可以在像vold或者其它一樣啟動和停止。這樣就更符合Android精神。
總結
以上是生活随笔為你收集整理的关于打印过程中强制移除打印机的处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 手机运营商mcc-mnc检索
- 下一篇: 硬件在环仿真(HiL)测试介绍