View | Details | Raw Unified | Return to ticket 6859
Collapse All | Expand All

(-)a/src/plugins/jobcomp/elasticsearch/jobcomp_elasticsearch.c (+77 lines)
Lines 39-45 Link Here
39
#include "config.h"
39
#include "config.h"
40
40
41
#include <curl/curl.h>
41
#include <curl/curl.h>
42
#include <ctype.h>
42
#include <fcntl.h>
43
#include <fcntl.h>
44
#include <iconv.h>
43
#include <inttypes.h>
45
#include <inttypes.h>
44
#include <grp.h>
46
#include <grp.h>
45
#include <pwd.h>
47
#include <pwd.h>
Lines 887-892 extern int slurm_jobcomp_log_record(struct job_record *job_ptr) Link Here
887
	return SLURM_SUCCESS;
889
	return SLURM_SUCCESS;
888
}
890
}
889
891
892
static void _to_utf8(struct job_node *jnode)
893
{
894
	char *converted = NULL, *converted_start = NULL, *inbuf_start = NULL;
895
	size_t from_len, to_len, ncc;
896
	iconv_t cd;
897
898
	cd = iconv_open("UTF-8//TRANSLIT", "ISO-8859-1");
899
	if (cd == (iconv_t)-1) {
900
		if (errno == EINVAL)
901
			error("%s: enconding conversion not supported",
902
			      __func__);
903
		else
904
			error("%s: conversion descriptor allocation failure",
905
			      __func__);
906
		return;
907
	}
908
909
	inbuf_start = jnode->serialized_job;
910
	from_len = strlen(jnode->serialized_job) + 1;
911
	to_len = from_len * 4;
912
	converted = malloc(to_len);
913
	converted_start = converted;
914
	ncc = iconv(cd, &jnode->serialized_job, &from_len, &converted, &to_len);
915
	if (ncc == (size_t)-1) {
916
		if (errno == E2BIG)
917
			error("%s: there is not sufficient room at *outbuf.",
918
			      __func__);
919
		else if (errno == EILSEQ)
920
			error("%s: an invalid multibyte sequence has been encountered in the input.",
921
			      __func__);
922
		else if (errno == EINVAL)
923
			error("%s: an incomplete multibyte sequence has been encountered in the input.",
924
			      __func__);
925
		else
926
			error("%s: character conversion failed: %m", __func__);
927
		goto cleanup;
928
	}
929
930
	if (slurm_get_debug_flags() & DEBUG_FLAG_ESEARCH)
931
		info("%s: %zu bytes converted (%zu non-reversible)", __func__,
932
		     to_len, ncc);
933
	xfree(inbuf_start);
934
	jnode->serialized_job = xstrdup(converted_start);
935
936
937
cleanup:
938
	free(converted_start);
939
	iconv_close(cd);
940
941
	return;
942
}
943
944
static void _strip_control_chars(char * str)
945
{
946
	unsigned char *ptr, *s = (void*)str;
947
	ptr = s;
948
	while (*s != '\0') {
949
		if (!iscntrl(*s))
950
			*(ptr++) = *s;
951
		s++;
952
	}
953
	*ptr = '\0';
954
}
955
956
static void _soft_sanitize(struct job_node *jnode)
957
{
958
	_strip_control_chars(jnode->serialized_job);
959
	if (xstrstr(jnode->serialized_job, "\"job_name\":\"icon\"\","))
960
		xstrsubstitute(jnode->serialized_job, "\"job_name\":\"icon\"\",", "\"job_name\":\"icon\",");
961
	if (xstrstr(jnode->serialized_job, "\"jobname\":\"icon\"\","))
962
		xstrsubstitute(jnode->serialized_job, "\"jobname\":\"icon\"\",", "\"jobname\":\"icon\",");
963
	_to_utf8(jnode);
964
}
965
890
extern void *_process_jobs(void *x)
966
extern void *_process_jobs(void *x)
891
{
967
{
892
	ListIterator iter;
968
	ListIterator iter;
Lines 910-915 extern void *_process_jobs(void *x) Link Here
910
				} else {
986
				} else {
911
					jnode->last_index_retry = now;
987
					jnode->last_index_retry = now;
912
					fail_cnt++;
988
					fail_cnt++;
989
					_soft_sanitize(jnode);
913
				}
990
				}
914
			} else
991
			} else
915
				wait_retry_cnt++;
992
				wait_retry_cnt++;

Return to ticket 6859