aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2009-06-22 21:07:27 +0000
committerMichael Albinus2009-06-22 21:07:27 +0000
commitb41b828aacce589aad24cd81fe3e1c111fa7c642 (patch)
tree559f90629cf7f02d2d91accf3856cb8f3b171601
parent6fa5052f067af617cb42f876afa02d02586953a0 (diff)
downloademacs-b41b828aacce589aad24cd81fe3e1c111fa7c642.tar.gz
emacs-b41b828aacce589aad24cd81fe3e1c111fa7c642.zip
* net/tramp-compat.el (tramp-compat-split-string)
(tramp-compat-process-running-p): New defuns.
-rw-r--r--lisp/net/tramp-compat.el51
1 files changed, 51 insertions, 0 deletions
diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el
index 0de7b0d2554..a4b3dc7728f 100644
--- a/lisp/net/tramp-compat.el
+++ b/lisp/net/tramp-compat.el
@@ -233,6 +233,57 @@ Add the extension of FILENAME, if existing."
233 (setq tree (cdr tree))) 233 (setq tree (cdr tree)))
234 (nconc (nreverse result) tree)))) 234 (nconc (nreverse result) tree))))
235 235
236(defun tramp-compat-split-string (string pattern)
237 "Like `split-string' but omit empty strings.
238In Emacs, (split-string \"/foo/bar\" \"/\") returns (\"foo\" \"bar\").
239This is, the first, empty, element is omitted. In XEmacs, the first
240element is not omitted."
241 (delete "" (split-string string pattern)))
242
243(defun tramp-compat-process-running-p (process-name)
244 "Returns `t' if system process PROCESS-NAME is running for `user-login-name'."
245 (when (stringp process-name)
246 (cond
247 ;; GNU Emacs 22 on w32.
248 ((fboundp 'w32-window-exists-p)
249 (funcall (symbol-function 'w32-window-exists-p)
250 process-name process-name))
251
252 ;; GNU Emacs 23.
253 ((and (fboundp 'list-system-processes) (fboundp 'process-attributes))
254 (let (result)
255 (dolist (pid (funcall (symbol-function 'list-system-processes)) result)
256 (let ((attributes
257 (funcall (symbol-function 'process-attributes) pid)))
258 (when
259 (and (string-equal
260 (cdr (assoc 'user attributes)) (user-login-name))
261 ;; The returned command name could be truncated
262 ;; to 15 characters. Therefore, we cannot check
263 ;; for `string-equal'.
264 (string-match
265 (concat "^" (regexp-quote (cdr (assoc 'comm attributes))))
266 process-name))
267 (setq result t))))))
268
269 ;; Fallback, if there is no Lisp support yet.
270 (t (let ((default-directory
271 (if (file-remote-p default-directory)
272 (tramp-compat-temporary-file-directory)
273 default-directory))
274 (unix95 (getenv "UNIX95"))
275 result)
276 (setenv "UNIX95" "1")
277 (when (member
278 (user-login-name)
279 (tramp-compat-split-string
280 (shell-command-to-string
281 (format "ps -C %s -o user=" process-name))
282 "[ \f\t\n\r\v]+"))
283 (setq result t))
284 (setenv "UNIX95" unix95)
285 result)))))
286
236(provide 'tramp-compat) 287(provide 'tramp-compat)
237 288
238;;; TODO: 289;;; TODO: